-
Notifications
You must be signed in to change notification settings - Fork 28
/
posts_controller.php
142 lines (126 loc) · 3.02 KB
/
posts_controller.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
/**
* PostsController class
*
* @uses AppController
* @package mongodb
* @subpackage mongodb.samples.controllers
*/
class PostsController extends AppController {
public $Post;
/**
* name property
*
* @var string 'Posts'
* @access public
*/
public $name = 'Posts';
/**
* index method
*
* @return void
* @access public
*/
public function index() {
$params = array(
'fields' => array('title', 'body', 'hoge'),
//'fields' => array('Post.title', ),
//'conditions' => array('title' => 'hehe'),
//'conditions' => array('hoge' => array('$gt' => '10', '$lt' => '34')),
//'order' => array('title' => 1, 'body' => 1),
'order' => array('_id' => -1),
'limit' => 35,
'page' => 1,
);
$results = $this->Post->find('all', $params);
//$result = $this->Post->find('count', $params);
$this->set(compact('results'));
}
/**
* add method
*
* @return void
* @access public
*/
public function add() {
if (!empty($this->data)) {
$this->Post->create();
if ($this->Post->save($this->data)) {
$this->flash(__('Post saved.', true), array('action' => 'index'));
} else {
}
}
}
/**
* edit method
*
* @param mixed $id null
* @return void
* @access public
*/
public function edit($id = null) {
if (!$id && empty($this->data)) {
$this->flash(__('Invalid Post', true), array('action' => 'index'));
}
if (!empty($this->data)) {
if ($this->Post->save($this->data)) {
$this->flash(__('The Post has been saved.', true), array('action' => 'index'));
} else {
}
}
if (empty($this->data)) {
$this->data = $this->Post->read(null, $id);
//$this->data = $this->Post->find('first', array('conditions' => array('_id' => $id)));
}
}
/**
* delete method
*
* @param mixed $id null
* @return void
* @access public
*/
public function delete($id = null) {
if (!$id) {
$this->flash(__('Invalid Post', true), array('action' => 'index'));
}
if ($this->Post->delete($id)) {
$this->flash(__('Post deleted', true), array('action' => 'index'));
} else {
$this->flash(__('Post deleted Fail', true), array('action' => 'index'));
}
}
/**
* deleteall method
*
* @return void
* @access public
*/
public function deleteall() {
$conditions = array('title' => 'aa');
if ($this->Post->deleteAll($conditions)) {
$this->flash(__('Post deleteAll success', true), array('action' => 'index'));
} else {
$this->flash(__('Post deleteAll Fail', true), array('action' => 'index'));
}
}
/**
* updateall method
*
* @return void
* @access public
*/
public function updateall() {
$conditions = array('title' => 'ichi2' );
$field = array('title' => 'ichi' );
if ($this->Post->updateAll($field, $conditions)) {
$this->flash(__('Post updateAll success', true), array('action' => 'index'));
} else {
$this->flash(__('Post updateAll Fail', true), array('action' => 'index'));
}
}
public function createindex() {
$mongo = ConnectionManager::getDataSource($this->Post->useDbConfig);
$mongo->ensureIndex($this->Post, array('title' => 1));
}
}