1. Go to this page and download the library: Download lox/pheasant 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/ */
lox / pheasant example snippets
use \Pheasant;
use \Pheasant\Types;
class Post extends DomainObject
{
public function properties()
{
return array(
'postid' => new Types\SequenceType(),
'title' => new Types\StringType(255, 'ray(
'Author' => Author::hasOne('authorid')
);
}
}
class Author extends DomainObject
{
public function properties()
{
return array(
'authorid' => new Types\SequenceType(),
'fullname' => new Types\StringType(255, 'rray('fullname'=>'Lachlan'));
$post = new Post(array('title'=>'My Post', 'author'=>$author));
// save objects
$author->save();
$post->save();
echo $post->title; // returns 'My Post'
echo $post->Author->fullname; // returns 'Lachlan'
// all users
$users = User::all();
// all users named frank
$users = User::find('firstname = ?', 'frank');
// any fields can be used in finders, this translates to above
$users = User::findByFirstName('frank');
// a single user named frank
$users = User::one('firstname = ?', 'frank');
// a user by primary key
$user = User::byId(1);
// all comments by a user (if user hasmany comment)
$comments = User::byId(1)->Comment;
// to prevent the n+1 query issue, eager load the relation:
$users = User::all()->
use \Pheasant;
Class User extends DomainObject
{
public function scopes()
{
return array(
'active' => function($collection){
$collection->filter('last_login_date >= ?', strtotime('30 days ago'));
},
);
}
}
// Scopes may be used by invoking them like methods
User::all()->active()
//=> Returns all active users
use \Pheasant;
use \Pheasant\Events;
use \Pheasant\Types;
class Post extends DomainObject
{
public function properties()
{
return array(
'postid' => new Types\SequenceType(),
'title' => new Types\StringType(255),
'timecreated' => new Types\IntegerType(11),
));
}
public function beforeCreate($post)
{
$d->timecreated = time();
}
}
\Pheasant::transaction(function() {
$post = new Post(array('title'=>'First Post!'));
$post->save();
});
$post = new Post(array('title'=>'First Post!'));
$post->transaction(function($obj) {
$obj->save();
});
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.