1. Go to this page and download the library: Download mawelous/yamop library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mawelous / yamop example snippets
$connection = new \MongoClient( 'your_host' );
\Mawelous\Yamop\Mapper::setDatabase( $connection->your_db_name );
class User extends \Mawelous\Yamop\Model
{
protected static $_collectionName = 'users';
}
object(User)[44]
public '_id' =>
object(MongoId)[46]
public '$id' => string '51b6ea4fb7846c9410000001' (length=24)
public 'name' => string 'John Doe' (length=8)
public 'birthdate' =>
object(MongoDate)[47]
public 'sec' => int 1369484125
public 'usec' => int 0
public 'email' => string '[email protected]' (length=18)
public 'id' => string '51b6ea4fb7846c9410000001' (length=24)
// properties as array
$user = new User( array( 'name' => 'John', 'email' => '[email protected]' ) );
// or each property separately
$user = new User;
$user->name = 'John';
$user->email = '[email protected]';
class User extends \Mawelous\Yamop\Model
{
protected static $_collectionName = 'users';
// One Address object embedded in address property
protected static $_embeddedObject = array (
'address' => 'Address',
);
// Many Notification objects embedded in array that is kept ass notifications
protected static $_embeddedObjectList = array (
'notifications' => 'Notification',
);
}
// contest_id property holds MongoId of related Contest object
$user = User::findById( new MongoId( $stringId ) )->joinOne( 'contest_id', 'Contest', 'contest')
// and there it is
$contest = $user->contest;
// contests field is array of MongoIds
$user = User::findById( new MongoId( $stringId ) )->joinMany( 'contests', 'Contest', 'contests')
// and you have array of contests there
$contests = $user->contests;
class User extends Model
{
...
public static $timestamps = true;
....
//date as string
$user->getDate( 'birthdate', 'Y/m/d' );
//time as string
$user->getTime( 'created_at', 'Y/m/d H:i');
//time as string using default format set in $dateFormat
$user->getTime( 'created_at' );