本文整理汇总了PHP中Jelly::model_name方法的典型用法代码示例。如果您正苦于以下问题:PHP Jelly::model_name方法的具体用法?PHP Jelly::model_name怎么用?PHP Jelly::model_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Jelly
的用法示例。
在下文中一共展示了Jelly::model_name方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: as_array
/**
* Return all of the rows in the result as an array.
*
* @param string column for associative keys
* @param string column for values
* @return array
*/
public function as_array($key = NULL, $value = NULL)
{
$model = Jelly::model_name($this->_model);
foreach (array('key', 'value') as $var) {
// Only alias meta-aliases
if (${$var} && FALSE !== strpos(${$var}, ':')) {
${$var} = Jelly::meta_alias($model, ${$var}, NULL);
}
}
return $this->_result->as_array($key, $value);
}
示例2: __construct
/**
* Constructs a new Jelly_Builder instance.
*
* $model is not actually allowed to be NULL. It has
* a default because PHP throws strict errors otherwise.
*
* @param string $model
*/
public function __construct($model = NULL, $type = NULL)
{
parent::__construct();
if (!$model) {
throw new Kohana_Exception(get_class($this) . ' requires $model to be set in the constructor');
}
// Set the model and the initial from()
$this->_model = Jelly::model_name($model);
$this->_register_model();
// Default to loading as arrays
$this->as_object(FALSE);
// Save this for building the query later on
$this->_type = $type;
}
示例3: __construct
/**
* Constructs a new Jelly_Builder instance.
*
* $model is not actually allowed to be NULL. It has
* a default because PHP throws strict errors otherwise.
*
* @throws Kohana_Exception
* @param string|null $model
* @param mixed|null $key
*/
public function __construct($model = NULL, $key = NULL)
{
parent::__construct();
if (!$model) {
throw new Kohana_Exception(get_class($this) . ' requires $model to be set in the constructor');
}
// Set the model and the initial from()
$this->_model = Jelly::model_name($model);
$this->_meta = Jelly::meta($this->_model);
$this->_initialize();
// Default to using our key
if ($key !== NULL) {
$this->key($key);
}
}
示例4: __toString
/**
* How this object reacts when converted to a string
*
* @return string
*/
public function __toString()
{
return 'Jelly_Model: ' . Jelly::model_name($this->_model) . ' - ' . $this->name();
}
示例5: testModelNameConversion
/**
* @dataProvider providerModelNameConversion
*/
public function testModelNameConversion($input, $expected)
{
$this->assertEquals($expected, Jelly::model_name($input));
}
示例6: get_relations
private function get_relations(Jelly_Model $model)
{
$model_name = Jelly::model_name($model);
$model_id = $model->id();
$belongs_to = array();
$children = array();
$fields = $model->meta()->fields();
foreach ($fields as $field) {
if ($field instanceof Jelly_Field_Relationship) {
// TODO: Shouldn't Field_Relationship work? But it's not inherited through...
if (isset($field->ignore_for_delete) && $field->ignore_for_delete) {
continue;
}
$related_model = $field->foreign['model'];
$related_model_fields = Jelly::meta($related_model)->fields();
foreach ($related_model_fields as $related_model_field) {
if ($related_model_field instanceof Field_BelongsTo && $related_model_field->foreign['model'] == $model_name) {
$dependencies = Jelly::select($related_model)->where($related_model_field->name, '=', $model_id)->execute();
if ($field instanceof Field_HasManyUniquely) {
$add_to_array = 'children';
$link_route = Route::get('kadmium_child_edit');
$uri_params = array('controller' => $model_name, 'child_action' => 'edit', 'action' => $related_model, 'parent_id' => $model_id);
} else {
$add_to_array = 'belongs_to';
$link_route = Route::get('kadmium');
$uri_params = array('controller' => $related_model, 'action' => 'edit');
}
foreach ($dependencies as $dependency) {
array_push(${$add_to_array}, array('model' => $related_model, 'name' => $dependency->name(), 'link' => $link_route->uri($uri_params + array('id' => $dependency->id()))));
}
} elseif ($related_model_field instanceof Field_ManyToMany && $related_model_field->foreign['model'] == $model_name) {
$get_links = Jelly::select($related_model_field->through['model'])->select($related_model_field->through['columns'][0])->where($related_model_field->through['columns'][1], '=', $model_id)->execute();
foreach ($get_links as $link) {
$related = $link->{$related_model_field->through['columns'][0]};
if (!$related instanceof Jelly_Model) {
$related = Jelly::select($related_model, $related);
}
$belongs_to[] = array('model' => $related_model, 'name' => $related->name(), 'link' => Route::get('kadmium')->uri(array('controller' => $related_model, 'action' => 'edit', 'id' => $related->id())));
}
}
}
}
}
return array($belongs_to, $children);
}
示例7: test_model_name
/**
* Tests Jelly::model_name().
*
* @dataProvider provider_model_name
*/
public function test_model_name($model, $expected)
{
$this->assertSame($expected, Jelly::model_name($model));
}
示例8: register
/**
* Automatically loads a model, if it exists,
* into the meta table.
*
* Models are not required to register
* themselves; it happens automatically.
*
* @param string $model
* @return boolean
*/
public static function register($model)
{
$class = Jelly::class_name($model);
$model = Jelly::model_name($model);
// Don't re-initialize!
if (isset(Jelly::$_models[$model])) {
return TRUE;
}
// Can we find the class?
if (class_exists($class)) {
// Prevent accidentally trying to load ORM or Sprig models
if (!is_subclass_of($class, "Jelly_Model")) {
return FALSE;
}
} else {
return FALSE;
}
// Load it into the registry
Jelly::$_models[$model] = $meta = new Jelly_Meta($model);
// Let the intialize() method override defaults.
call_user_func(array($class, 'initialize'), $meta);
// Finalize the changes
$meta->finalize($model);
return TRUE;
}
示例9: __construct
/**
* Model not found or no access
*
* @param Jelly_Model $model
* @param integer $id
*/
public function __construct(Jelly_Model $model, $id = 0)
{
parent::__construct('Model not found: :model #:id', array(':id' => $id, ':model' => Jelly::model_name($model)));
}
示例10: __toString
/**
* Returns a string representation of the collection.
*
* @return string
*/
public function __toString()
{
return get_class($this) . ': ' . Jelly::model_name($this->_model) . ' (' . $this->count() . ')';
}
示例11: model
/**
* Return model specific route
*
* @param Jelly_Model $model
* @param string $action
* @param string $params
* @param string $route Defaults to model name
* @return string
*/
public static function model(Jelly_Model $model, $action = '', $params = null, $route = null)
{
return Route::get($route ? $route : Jelly::model_name($model))->uri(array('id' => self::model_id($model), 'action' => $action, 'params' => $params));
}
示例12: array
<?php
echo Html::anchor(Route::get('kadmium_child_edit')->uri(array('controller' => Request::current()->controller, 'child_action' => 'edit', 'parent_id' => $model->id(), 'action' => $field->foreign['model'], 'id' => 0)), 'Add a new ' . Inflector::humanize(Jelly::model_name($value->current())), array('class' => 'add' . $lb_class));
示例13: foreach
foreach ($value as $child_model) {
?>
<li rel="<?php
echo $child_model->id();
?>
">
<?php
if ($is_img_list) {
$image_field = $child_model->meta()->fields($field->list_as_thumbnails);
$path = count($image_field->thumbnails) ? $image_field->thumbnails[0]['path'] : $image_field->path;
$link_contents = Html::image(str_replace(DOCROOT, '', $path) . $child_model->get($field->list_as_thumbnails), array('alt' => $child_model->name(), 'title' => $child_model->name()));
} else {
$link_contents = $child_model->name();
}
echo '<span>' . $link_contents . '</span>';
echo Html::anchor(Route::get('kadmium_child_edit')->uri(array('controller' => Request::current()->controller, 'child_action' => 'edit', 'parent_id' => $model->id(), 'action' => Jelly::model_name($child_model), 'id' => $child_model->id())), 'edit', array('class' => 'edit' . $lb_class));
?>
</li>
<?php
}
?>
</ul>
<ul class="has-many-uniquely" rel="<?php
echo $name;
?>
">
<li>
<span>
<?php
echo View::factory($add_link_view, array('model' => $model, 'field' => $field, 'value' => $value, 'lb_class' => $lb_class));
?>