Mvc\Model::DIRTY_STATE_DETACHED

integer DIRTY_STATE_DETACHED

Mvc\Model::create

public create ([mixed $data], [mixed $whiteList]) Inserts a model instance. If the instance already exists in the persistence it will throw an exception Returning true on success or false otherwise. //Creating a new robot $robot = new Robots(); $robot->type = 'mechanical'; $robot->name = 'Astro Boy'; $robot->year = 1952; $robot->create(); //Passing an array to create $robot = new Robots(); $robot->create(array( 'type' => 'mechanical', 'name' => 'Astro Boy', 'ye

Mvc\Model::count

public static mixed count ([array $parameters]) Allows to count how many records match the specified conditions //How many robots are there? $number = Robots::count(); echo "There are ", $number, "\n"; //How many mechanical robots are there? $number = Robots::count("type = 'mechanical'"); echo "There are ", $number, " mechanical robots\n";

Mvc\Model::cloneResult

public static Phalcon\Mvc\ModelInterface cloneResult (Phalcon\Mvc\ModelInterface $base, array $data, [int $dirtyState]) Assigns values to a model from an array returning a new model $robot = Phalcon\Mvc\Model::cloneResult(new Robots(), array( 'type' => 'mechanical', 'name' => 'Astro Boy', 'year' => 1952 ));

Mvc\Model::assign

public Phalcon\Mvc\Model assign (array $data, [mixed $dataColumnMap], [array $whiteList]) Assigns values to a model from an array $robot->assign(array( 'type' => 'mechanical', 'name' => 'Astro Boy', 'year' => 1952 )); //assign by db row, column map needed $robot->assign($dbRow, array( 'db_type' => 'type', 'db_name' => 'name', 'db_year' => 'year' )); //allow assign only name and year $robot->assign($_POST, null, array('name', 'year');

Mvc\Model::cloneResultMap

public static cloneResultMap (Phalcon\Mvc\ModelInterface | Phalcon\Mvc\Model\Row $base, array $data, array $columnMap, [int $dirtyState], [boolean $keepSnapshots]) Assigns values to a model from an array returning a new model. $robot = \Phalcon\Mvc\Model::cloneResultMap(new Robots(), array( 'type' => 'mechanical', 'name' => 'Astro Boy', 'year' => 1952 ));

Mvc\Model::average

public static double average ([array $parameters]) Allows to calculate the average value on a column matching the specified conditions //What's the average price of robots? $average = Robots::average(array('column' => 'price')); echo "The average price is ", $average, "\n"; //What's the average price of mechanical robots? $average = Robots::average(array("type='mechanical'", 'column' => 'price')); echo "The average price of mechanical robots is ", $average, "\n";

Mvc\Model::appendMessage

public appendMessage (Phalcon\Mvc\Model\MessageInterface $message) Appends a customized message on the validation process use Phalcon\Mvc\Model; use Phalcon\Mvc\Model\Message as Message; class Robots extends Model { public function beforeSave() { if ($this->name == 'Peter') { $message = new Message("Sorry, but a robot cannot be named Peter"); $this->appendMessage($message); } } }

Mvc\Model::addBehavior

public addBehavior (Phalcon\Mvc\Model\BehaviorInterface $behavior) Setups a behavior in a model <?php use Phalcon\Mvc\Model; use Phalcon\Mvc\Model\Behavior\Timestampable; class Robots extends Model { public function initialize() { $this->addBehavior(new Timestampable(array( 'onCreate' => array( 'field' => 'created_at', 'format' => 'Y-m-d' ) ))); } }

Mvc\Model

implements Phalcon\Mvc\EntityInterface, Phalcon\Mvc\ModelInterface, Phalcon\Mvc\Model\ResultInterface, Phalcon\Di\InjectionAwareInterface, Serializable, JsonSerializable Source on GitHub Phalcon\Mvc\Model connects business objects and database tables to create a persistable domain model where logic and data are presented in one wrapping. It‘s an implementation of the object-relational mapping (ORM). A model represents the information (data) of the application and the rules to manipulate that da