本文整理汇总了PHP中Jelly::alias方法的典型用法代码示例。如果您正苦于以下问题:PHP Jelly::alias方法的具体用法?PHP Jelly::alias怎么用?PHP Jelly::alias使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Jelly
的用法示例。
在下文中一共展示了Jelly::alias方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _column
/**
* This is an internal method used for aliasing only things coming
* to the query builder, since they can come in so many formats.
*
* $value is passed so the :unique_key meta alias can be used.
*
* @param string $field
* @param boolean $join
* @param mixed $value
* @return string
*/
protected function _column($field, $join = TRUE, $value = NULL)
{
$model = NULL;
// Check for functions
if (strpos($field, '"') !== FALSE) {
// Quote the column in FUNC("ident") identifiers
return preg_replace('/"(.+?)"/e', '"\\"".$this->_column("$1")."\\""', $field);
}
// Test for Database Expressions
if ($field instanceof Database_Expression) {
return $field;
}
// Set if we find this is a reference to a joined field
$join_table_alias = FALSE;
// Field has no model
if (strpos($field, '.') === FALSE) {
// If we have a meta alias with no model use this model to resolve it
// or if we have a valid field for this model assume that's what we mean
if (strpos($field, ':') !== FALSE or $this->_meta and $this->_meta->fields($field)) {
$field = $this->_model . '.' . $field;
} else {
// This is not a model field or meta alias, so don't bother trying to alias it and
// return it as it is
return $field;
}
} else {
list($model, $field) = explode('.', $field, 2);
// Check to see if the 'model' passed is actually a relationship alias
if ($field_object = $this->_meta->fields($model) and $field_object instanceof Jelly_Field_Behavior_Joinable) {
// The model specified looks like a relationship alias in this context
// that means we alias the field name to a column but use the join alias for the table
$join_table_alias = Jelly::join_alias($field_object);
// Change the field to use the appropriate model so it can be properly aliased
$field = $field_object->foreign['model'] . '.' . $field;
} else {
// Put field back together
$field = $model . '.' . $field;
}
}
$alias = Jelly::alias($field, $value);
if ($join_table_alias) {
// Replace the actual table with the join alias
$alias['table'] = $join_table_alias;
}
if ($join) {
return implode('.', $alias);
} else {
return $alias['column'];
}
}
示例2: testFields
/**
* Tests aliasing fields to their column using the normal syntax
*
* @dataProvider providerFields
*/
public function testFields($input, $table, $column)
{
$alias = Jelly::alias($input);
$this->assertEquals($table, $alias['table']);
$this->assertEquals($column, $alias['column']);
}