API documentationTable Of ContentsPrevious topicNext topicThis Page |
Models¶Models is database entities. You can read more about them in Phalcon documentation. But PhalconEye has little difference in models: annotations, changed methods (get, getFirst), etc. Example of model: <?php
namespace Core\Model;
use Engine\Db\AbstractModel;
/**
* Access.
*
* @category PhalconEye
* @package Core\Model
* @author Ivan Vorontsov <ivan.vorontsov@phalconeye.com>
* @copyright 2013-2014 PhalconEye Team
* @license New BSD License
* @link http://phalconeye.com/
*
* @Source("access")
* @BelongsTo("role_id", "User\Model\Role", "id")
*/
class Access extends AbstractModel
{
/**
* @Primary
* @Identity
* @Column(type="string", nullable=false, column="object", size="55")
*/
public $object;
/**
* @Primary
* @Column(type="string", nullable=false, column="action", size="255")
*/
public $action;
/**
* @Primary
* @Column(type="integer", nullable=false, column="role_id", size="11")
*/
public $role_id;
/**
* @Column(type="string", nullable=true, column="value", size="25")
*/
public $value;
}
Maybe you noticed that access to model fields possible through public modifier of this fields, but not through public methods. This was made coz of database fields naming conversion. In that case you can fast search through code and understand what field is responsible for. If you don’t like this idea - you can change AbstractModel and add your own magic method (__call) or add methods to your model. Annotations¶Annotations are needed as metadata and for schema generation feature.
Methods¶Here is some useful methods: <?php
// Get table name in database (for queries and other stuff).
$tableName = Access::getTableName();
// Methods "get" and "getFirst" was modified with sprintf method inside.
// Parameters:
// 1. Condition with placeholders
// 2. Parameter for condition placeholders.
// 3. Order by field.
// 4. Limit.
$access1 = Access::get('action = "%s" AND value = "%s"', ["edit", "allowed"], "role_id", 100)
$access2 = Access::getFirst('module = "%s" AND name = "%s"', ["edit", "allowed"], "role_id", 100)
// Create builder for access table, returns object of Phalcon\Mvc\Model\Query\Builder class. First param - table alias in query builder.
$builder = Access::getBuilder("tableAlias");
// Get row identity.
$id = $access1->getId();
|