本文整理汇总了PHP中Jelly::model_prefix方法的典型用法代码示例。如果您正苦于以下问题:PHP Jelly::model_prefix方法的具体用法?PHP Jelly::model_prefix怎么用?PHP Jelly::model_prefix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Jelly
的用法示例。
在下文中一共展示了Jelly::model_prefix方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: finalize
/**
* This is called after initialization to
* finalize any changes to the meta object.
*
* @param string $model
* @return
*/
public function finalize($model)
{
if ($this->_initialized) {
return;
}
// Set up event system
$this->_events = new Jelly_Event($model);
// Set the name of a possible behavior class
$behavior_class = Jelly::behavior_prefix() . $model;
// See if we have a special behavior class to use
if (class_exists($behavior_class)) {
// Load behavior
$behavior = new $behavior_class();
if (!in_array($behavior, $this->_behaviors)) {
// Add to behaviors
$this->_behaviors[] = $behavior;
}
}
foreach ($this->_behaviors as $name => $behavior) {
if (!$behavior instanceof Jelly_Behavior) {
throw new Kohana_Exception('Behavior at index [ :key ] is not an instance of Jelly_Behavior, :type found.', array(':type' => is_object($behavior) ? 'instance of ' . get_class($behavior) : gettype($behavior), ':key' => $name));
}
// Initialize behavior
$behavior->initialize($this->_events, $model, $name);
}
// Allow modification of this meta object by the behaviors
$this->_events->trigger('meta.before_finalize', $this);
// Ensure certain fields are not overridden
$this->_model = $model;
$this->_columns = $this->_defaults = $this->_field_cache = $this->_aliases = array();
if (!$this->_errors_filename) {
// Default errors filename to the model's name
$this->_errors_filename = $this->_model;
}
// Table should be a sensible default
if (empty($this->_table)) {
$this->_table = Inflector::plural($model);
}
// See if we have a special builder class to use
if (empty($this->_builder)) {
$builder = Jelly::model_prefix() . 'builder_' . $model;
if (class_exists($builder)) {
$this->_builder = $builder;
} else {
$this->_builder = 'Jelly_Builder';
}
}
// Can we set a sensible foreign key?
if (empty($this->_foreign_key)) {
$this->_foreign_key = $model . '_id';
}
// Initialize all of the fields with their column and the model name
foreach ($this->_fields as $column => $field) {
// Allow aliasing fields
if (is_string($field)) {
if (isset($this->_fields[$field])) {
$this->_aliases[$column] = $field;
}
// Aliases shouldn't pollute fields
unset($this->_fields[$column]);
continue;
}
$field->initialize($model, $column);
// Ensure a default primary key is set
if ($field->primary and empty($this->_primary_key)) {
$this->_primary_key = $column;
}
// Search for a polymorphic key
if (!empty($field->polymorphic)) {
$this->_polymorphic_key = $field->name;
// Add this class as a child if it hasn't been added yet
if (!in_array($this->_model, $this->_children)) {
$this->_children[] = $this->_model;
}
}
// Set the defaults so they're actually persistent
$this->_defaults[$column] = $field->default;
}
// Meta object is initialized and no longer writable
$this->_initialized = TRUE;
// Final meta callback
$this->_events->trigger('meta.after_finalize', $this);
}
示例2: model_name
/**
* Returns the model name of a class
*
* @param string|Jelly_Model $model
* @return string
*/
public static function model_name($model)
{
if ($model instanceof Jelly_Model) {
$model = get_class($model);
}
$prefix_length = strlen(Jelly::model_prefix());
// Compare the first parts of the names and chomp if they're the same
if (strtolower(substr($model, 0, $prefix_length)) === strtolower(Jelly::model_prefix())) {
$model = substr($model, $prefix_length);
}
return strtolower($model);
}
示例3: finalize
/**
* This is called after initialization to
* finalize any changes to the meta object.
*
* @return void
*/
public function finalize($model)
{
if ($this->initialized) {
return;
}
// Ensure certain fields are not overridden
$this->model = $model;
$this->columns = $this->defaults = $this->field_cache = $this->aliases = array();
// Table should be a sensible default
if (empty($this->table)) {
$this->table = inflector::plural($model);
}
// See if we have a special builder class to use
if (empty($this->builder)) {
$builder = Jelly::model_prefix() . 'builder_' . $model;
if (class_exists($builder)) {
$this->builder = $builder;
} else {
$this->builder = 'Jelly_Builder';
}
}
// Can we set a sensible foreign key?
if (empty($this->foreign_key)) {
$this->foreign_key = $model . '_id';
}
// Initialize all of the fields with their column and the model name
foreach ($this->fields as $column => $field) {
// Allow aliasing fields
if (is_string($field)) {
if (isset($this->fields[$field])) {
$this->aliases[$column] = $field;
}
// Aliases shouldn't pollute fields
unset($this->fields[$column]);
continue;
}
$field->initialize($model, $column);
// Ensure a default primary key is set
if ($field->primary and empty($this->primary_key)) {
$this->primary_key = $column;
}
// Set the defaults so they're actually persistent
$this->defaults[$column] = $field->default;
// Set the columns, so that we can access reverse database results properly
if (!array_key_exists($field->column, $this->columns)) {
$this->columns[$field->column] = array();
}
$this->columns[$field->column][] = $column;
}
// Meta object is initialized and no longer writable
$this->initialized = TRUE;
}