Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
0fea8a50
Commit
0fea8a50
authored
Dec 05, 2013
by
Paul Klimov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Mongo README and composer updated.
parent
c542d09d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
79 additions
and
2 deletions
+79
-2
README.md
extensions/mongo/README.md
+78
-1
composer.json
extensions/mongo/composer.json
+1
-1
No files found.
extensions/mongo/README.md
View file @
0fea8a50
...
@@ -37,4 +37,80 @@ to the require section of your composer.json.
...
@@ -37,4 +37,80 @@ to the require section of your composer.json.
Usage & Documentation
Usage & Documentation
---------------------
---------------------
This extension adds
[
MongoDb
](
http://www.mongodb.org/
)
data storage support for the Yii2 framework.
This extension adds
[
MongoDB
](
http://www.mongodb.org/
)
data storage support for the Yii2 framework.
Note: extension requires
[
MongoDB PHP Extension
](
http://us1.php.net/manual/en/book.mongo.php
)
version 1.3.0 or higher.
To use this extension, simply add the following code in your application configuration:
```
php
return
[
//....
'components'
=>
[
'mongo'
=>
[
'class'
=>
'\yii\mongo\Connection'
,
'dsn'
=>
'mongodb://developer:password@localhost:27017/mydatabase'
,
],
],
];
```
This extension provides ActiveRecord solution similar ot the
[
[\yii\db\ActiveRecord
]
].
To declare an ActiveRecord class you need to extend
[
[\yii\mongo\ActiveRecord
]
] and
implement the
`collectionName`
and 'attributes' methods:
```
php
use
yii\mongo\ActiveRecord
;
class
Customer
extends
ActiveRecord
{
/**
* @return string the name of the index associated with this ActiveRecord class.
*/
public
static
function
collectionName
()
{
return
'customer'
;
}
/**
* @return array list of attribute names.
*/
public
function
attributes
()
{
return
[
'name'
,
'email'
,
'address'
,
'status'
];
}
}
```
You can use
[
[\yii\data\ActiveDataProvider
]
] with the
[
[\yii\mongo\Query
]
] and
[
[\yii\mongo\ActiveQuery
]
]:
```
php
use
yii\data\ActiveDataProvider
;
use
yii\mongo\Query
;
$query
=
new
Query
;
$query
->
from
(
'customer'
)
->
where
([
'status'
=>
2
]);
$provider
=
new
ActiveDataProvider
([
'query'
=>
$query
,
'pagination'
=>
[
'pageSize'
=>
10
,
]
]);
$models
=
$provider
->
getModels
();
```
```
php
use
yii\data\ActiveDataProvider
;
use
app\models\Customer
;
$provider
=
new
ActiveDataProvider
([
'query'
=>
Customer
::
find
(),
'pagination'
=>
[
'pageSize'
=>
10
,
]
]);
$models
=
$provider
->
getModels
();
```
This extension supports
[
MongoGridFS
](
http://docs.mongodb.org/manual/core/gridfs/
)
via
classes at namespace "
\y
ii
\m
ongo
\f
ile".
\ No newline at end of file
extensions/mongo/composer.json
View file @
0fea8a50
...
@@ -20,7 +20,7 @@
...
@@ -20,7 +20,7 @@
"minimum-stability"
:
"dev"
,
"minimum-stability"
:
"dev"
,
"require"
:
{
"require"
:
{
"yiisoft/yii2"
:
"*"
,
"yiisoft/yii2"
:
"*"
,
"ext-mongo"
:
"
*
"
"ext-mongo"
:
"
>=1.3.0
"
},
},
"autoload"
:
{
"autoload"
:
{
"psr-0"
:
{
"yii
\\
mongo
\\
"
:
""
}
"psr-0"
:
{
"yii
\\
mongo
\\
"
:
""
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment