本文整理汇总了PHP中Sprig::__construct方法的典型用法代码示例。如果您正苦于以下问题:PHP Sprig::__construct方法的具体用法?PHP Sprig::__construct怎么用?PHP Sprig::__construct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sprig
的用法示例。
在下文中一共展示了Sprig::__construct方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Initialize the fields and add MPTT field defaults if not specified
* @return void
*/
protected function __construct()
{
// Initialize sprig (this will call _init() in the model)
parent::__construct();
// Check we don't have a composite primary Key
if (is_array($this->pk())) {
throw new Sprig_Exception('Sprig_MPTT does not support composite primary keys');
}
// Check Sprig MPTT fields exist, if not add defaults
foreach ($this->_fields as $name => $field) {
// Check the field extends Sprig_Field_MPTT
if ($field instanceof Sprig_Field_MPTT) {
if ($field instanceof Sprig_Field_MPTT_Left) {
$this->left_column = $name;
} elseif ($field instanceof Sprig_Field_MPTT_Right) {
$this->right_column = $name;
} elseif ($field instanceof Sprig_Field_MPTT_Level) {
$this->level_column = $name;
} elseif ($field instanceof Sprig_Field_MPTT_Scope) {
$this->scope_column = $name;
}
} elseif ($field instanceof Sprig_Field_MPTT_Related and !array_key_exists($name, $this->related) or !$field instanceof Sprig_Field_MPTT_Related and array_key_exists($name, $this->related)) {
unset($this->_fields[$name]);
}
}
// If any of the MPTT fields havn't been defined, create defaults
if (is_null($this->left_column)) {
$this->left_column = 'lft';
$this->_fields['lft'] = new Sprig_Field_MPTT_Left(array('column' => 'lft'));
}
if (is_null($this->right_column)) {
$this->right_column = 'rgt';
$this->_fields['rgt'] = new Sprig_Field_MPTT_Right(array('column' => 'rgt'));
}
if (is_null($this->level_column)) {
$this->level_column = 'lvl';
$this->_fields['lvl'] = new Sprig_Field_MPTT_Level(array('column' => 'lvl'));
}
if (is_null($this->scope_column)) {
$this->scope_column = 'scope';
$this->_fields['scope'] = new Sprig_Field_MPTT_Scope(array('column' => 'scope'));
}
$suffixes = array('root', 'parent', 'ancestors', 'children', 'first_child', 'last_child', 'descendants', 'siblings', 'leaves');
while (list($field) = each($this->related) and list(, $suffix) = each($suffixes)) {
if (!array_key_exists($field, $this->_fields)) {
$sprig_field = 'Sprig_Field_MPTT_' . ucwords($suffix);
$this->_fields[$field] = new $sprig_field(array('model' => $this->_model));
}
}
// Check we have default values for all (MPTT) fields (otherwise we cause errors)
foreach ($this->_fields as $name => $field) {
if ($field instanceof Sprig_Field_MPTT and !isset($this->_original[$name])) {
$this->_original[$name] = NULL;
}
}
}
示例2: __construct
/**
* Initialize the fields and add MPTT field defaults if not specified
* @return void
*/
protected function __construct()
{
// Initialize sprig (this will call _init() in the model)
parent::__construct();
// Check we don't have a composite primary Key
if (is_array($this->pk())) {
throw new Sprig_Exception('Sprig_MPTT does not support composite primary keys');
}
// Check Sprig MPTT fields exist, if not add defaults
foreach ($this->_fields as $name => $field) {
// Check the field extends Sprig_Field_MPTT
if ($field instanceof Sprig_Field_MPTT) {
if ($field instanceof Sprig_Field_MPTT_Left) {
$this->left_column = $name;
} elseif ($field instanceof Sprig_Field_MPTT_Right) {
$this->right_column = $name;
} elseif ($field instanceof Sprig_Field_MPTT_Level) {
$this->level_column = $name;
} elseif ($field instanceof Sprig_Field_MPTT_Scope) {
$this->scope_column = $name;
}
}
}
// If any of the MPTT fields havn't been defined, create defaults
if (is_null($this->left_column)) {
$this->left_column = 'lft';
$this->_fields['lft'] = new Sprig_Field_MPTT_Left(array('column' => 'lft'));
}
if (is_null($this->right_column)) {
$this->right_column = 'rgt';
$this->_fields['rgt'] = new Sprig_Field_MPTT_Right(array('column' => 'rgt'));
}
if (is_null($this->level_column)) {
$this->level_column = 'lvl';
$this->_fields['lvl'] = new Sprig_Field_MPTT_Level(array('column' => 'lvl'));
}
if (is_null($this->scope_column)) {
$this->scope_column = 'scope';
$this->_fields['scope'] = new Sprig_Field_MPTT_Scope(array('column' => 'scope'));
}
// Check we have default values for all (MPTT) fields (otherwise we cause errors)
foreach ($this->_fields as $name => $field) {
if ($field instanceof Sprig_Field_MPTT and !isset($this->_original[$name])) {
$this->_original[$name] = NULL;
}
}
}
示例3: __construct
public function __construct($id = NULL)
{
$this->_columns = Kohana::config($this->_config)->columns;
$this->_user_model = Kohana::config($this->_config)->user_model;
parent::__construct($id);
}