1
1
<?php namespace Blog \Functions ;
2
2
3
3
4
- function connect ($ config )
5
- {
4
+ function connect ($ config ){
6
5
try {
7
6
if ( !class_exists ('Mongo ' )){
8
7
echo ("The MongoDB PECL extension has not been installed or enabled " );
@@ -15,19 +14,12 @@ function connect($config)
15
14
return false ;
16
15
}
17
16
}
17
+ /**
18
+ * get one article by id
19
+ * @return array
20
+ */
21
+ function getById ($ id ,$ collection ,$ dbname ){
18
22
19
-
20
- /*function get($collection,$dbname)
21
- {
22
- $table = $dbname->selectCollection($collection);
23
- //$table = $dbname->$collection;
24
- $stmt = $table->find();
25
-
26
- return ($stmt->count() > 0) ? $stmt : false;
27
- }*/
28
-
29
- function getById ($ id ,$ collection ,$ dbname )
30
- {
31
23
$ table = $ dbname ->selectCollection ($ collection );
32
24
$ cursor = $ table ->find (array ('_id ' => new \MongoId ($ id )));
33
25
$ article = $ cursor ->getNext ();
@@ -37,8 +29,12 @@ function getById($id,$collection,$dbname)
37
29
}
38
30
return $ article ;
39
31
}
40
- function get ($ page ,$ collection ,$ dbname )
41
- {
32
+ /**
33
+ * get all data in collection and paginator
34
+ *
35
+ * @return multi array
36
+ */
37
+ function get ($ page ,$ collection ,$ dbname ){
42
38
43
39
$ currentPage = $ page ;
44
40
$ articlesPerPage = 5 ;
0 commit comments