本文整理汇总了PHP中CModel::__get方法的典型用法代码示例。如果您正苦于以下问题:PHP CModel::__get方法的具体用法?PHP CModel::__get怎么用?PHP CModel::__get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CModel
的用法示例。
在下文中一共展示了CModel::__get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __get
public function __get($name)
{
if ($this->hasAttribute($name)) {
return $this->_attributes[$name];
} else {
return parent::__get($name);
}
}
示例2: __get
/**
* PHP getter magic method.
*
* @param string $name
*
* @return mixed
*/
public function __get($name)
{
if (in_array($name, $this->attributeNames())) {
return $this->getAttribute($name);
} else {
return parent::__get($name);
}
}
示例3: __get
public function __get($name)
{
if (array_key_exists($name, $this->data)) {
return $this->data[$name];
} else {
return parent::__get($name);
}
}
示例4: __get
public function __get($name)
{
if (isset($this->_attributes[$name])) {
return $this->_attributes[$name];
} elseif (in_array($name, $this->attributeNames())) {
return null;
} else {
return parent::__get($name);
}
}
示例5: __get
/**
* PHP getter magic method.
* This method is overridden so that MongoDB document can be accessed like properties.
* @param string property name
* @return mixed property value
* @see getAttribute
*/
public function __get($name)
{
if ($name === 'id') {
return $this->_document['_id'];
} elseif (array_key_exists($name, $this->_document)) {
return $this->_document[$name];
} else {
return parent::__get($name);
}
}
示例6: __get
public function __get($name)
{
if (strpos($name, '[')) {
$basePropertyName = substr($name, 0, strpos($name, '['));
$index = substr($name, strpos($name, '[') + 1);
if (property_exists($this, $basePropertyName)) {
return ArrayUtil::getNestedValue($this->{$basePropertyName}, $index);
}
}
return parent::__get($name);
}
示例7: __get
/**
* (non-PHPdoc)
* @see yii/framework/CComponent::__get()
*/
public function __get($name)
{
if (isset($this->_attributes[$name])) {
return $this->_attributes[$name];
} elseif (isset($this->_related[$name])) {
return $this->_related[$name];
} elseif (array_key_exists($name, $this->relations())) {
return $this->_related[$name] = $this->getRelated($name);
} else {
try {
return parent::__get($name);
} catch (CException $e) {
return null;
}
}
}
示例8: __get
/**
* @see yii/framework/CComponent::__get()
* @param string $name
* @return mixed
*/
public function __get($name)
{
if (isset($this->_attributes[$name])) {
return $this->_attributes[$name];
}
if (isset($this->_related[$name])) {
return $this->_related[$name];
}
if (array_key_exists($name, $this->relations())) {
return $this->_related[$name] = $this->getRelated($name);
}
try {
return parent::__get($name);
} catch (CException $e) {
$getter = 'get' . $name;
if (method_exists($this, $getter)) {
throw $e;
} elseif (strncasecmp($name, 'on', 2) === 0 && method_exists($this, $name)) {
throw $e;
}
return null;
}
}
示例9: __get
/**
* PHP getter magic method.
* This method is overridden so that attributes can be accessed like properties.
* @param string $name property name
* @return mixed property value
*/
public function __get($name)
{
if (isset($this->_attributes[$name])) {
return $this->_attributes[$name];
// } else if(isset($this->_related[$name])) {
// return $this->_related[$name];
} else {
return parent::__get($name);
}
}
示例10: __get
/**
* @since v1.0.8
*/
public function __get($name)
{
if ($this->hasEmbeddedDocuments() && isset(self::$_embeddedConfig[get_class($this)][$name])) {
// Late creation of embedded documents on first access
if (is_null($this->_embedded->itemAt($name))) {
$docClassName = self::$_embeddedConfig[get_class($this)][$name];
$doc = new $docClassName($this->getScenario());
$doc->setOwner($this);
$this->_embedded->add($name, $doc);
}
return $this->_embedded->itemAt($name);
} else {
return parent::__get($name);
}
}
示例11: __get
/**
* PHP getter magic method.
* This method is overridden so that node/relationship properties can be accessed.
* @param string $name property name
* @return mixed property value
* @see getAttribute
*/
public function __get($name)
{
if (isset($this->_attributes[$name])) {
return $this->_attributes[$name];
} else {
if (isset($this->getMetaData()->properties[$name])) {
return null;
} else {
return parent::__get($name);
}
}
}
示例12: __get
/**
* PHP getter magic method.
* This method is overridden so that Resource Model attributes can be accessed like properties.
* @param string $name property name
* @return mixed property value
* @see getAttribute
*/
public function __get($name)
{
if (isset($this->_attributes[$name])) {
return $this->_attributes[$name];
} elseif ($this->getResourceSchema()->hasAttribute($name)) {
return null;
} elseif (isset($this->_linked[$name])) {
return $this->_linked[$name];
} elseif (isset($this->_links[$name])) {
return $this->getLinked($name);
} else {
return parent::__get($name);
}
}
示例13: __get
/**
* Волшебный геттер
* @param type $name
*/
public function __get($name)
{
// проверка на наличие маппинга свойства на поле БД
$mapping = $this->fieldsMapping();
if (array_key_exists($name, $mapping)) {
$name = $mapping[$name];
}
// проверяем, не обычное ли это поле
if (array_key_exists($name, $this->getRecord()->getItems())) {
// обходной маневр для конвертации mysql-дат в отечественные
$properties = $this->fieldsProperty();
if (array_key_exists($name, $properties)) {
$property = $properties[$name];
if (array_key_exists("type", $property)) {
if ($property["type"] == FIELD_MYSQL_DATE) {
$value = $this->getRecord()->getItemValue($name);
if (strpos($value, "0000-00-00") !== false) {
return "";
}
return date($property["format"], strtotime($value));
}
}
}
return $this->getRecord()->getItemValue($name);
}
// поле необычное.
$relations = $this->relations();
if (array_key_exists($name, $relations)) {
$relation = $relations[$name];
// разрешим не указывать
if (!array_key_exists("storageProperty", $relation)) {
$relation["storageProperty"] = "_" . $name;
}
if ($relation['relationPower'] == RELATION_HAS_ONE) {
$private = $relation['storageProperty'];
if (is_null($this->{$private})) {
$key_field = $relation['storageField'];
$key_value = $this->{$key_field};
$useManager = true;
if (array_key_exists("targetClass", $relation)) {
$targetClass = $relation["targetClass"];
$useManager = false;
} else {
$managerClass = $relation['managerClass'];
$managerGetter = $relation['managerGetObject'];
}
if ($useManager) {
$obj = $managerClass::$managerGetter($key_value);
} else {
$targetClass = "get" . mb_substr($targetClass, 1);
$obj = CBaseManager::$targetClass($key_value);
}
$this->{$private} = $obj;
}
return $this->{$private};
} elseif ($relation['relationPower'] == RELATION_HAS_MANY) {
$private = $relation['storageProperty'];
/**
* Проверим, вдруг разрешено использование кэш
* и данные кэше уже есть
*/
$useCache = false;
if (array_key_exists("useCache", $relation)) {
$useCache = $relation["useCache"];
}
if ($useCache) {
$cacheKey = get_class($this) . "_property_" . $name . "_" . $this->getId();
if (CApp::getApp()->cache->hasCache($cacheKey)) {
$valueFromCache = CApp::getApp()->cache->get($cacheKey);
$this->{$private} = $valueFromCache;
}
}
if (is_null($this->{$private})) {
$table = $relation['storageTable'];
$condition = $relation['storageCondition'];
$useManager = true;
if (array_key_exists("targetClass", $relation)) {
$targetClass = $relation["targetClass"];
$useManager = false;
} else {
$managerClass = $relation['managerClass'];
$managerGetter = $relation['managerGetObject'];
}
$managerOrder = null;
if (array_key_exists("managerOrder", $relation)) {
$managerOrder = $relation['managerOrder'];
}
$this->{$private} = new CArrayList();
foreach (CActiveRecordProvider::getWithCondition($table, $condition, $managerOrder)->getItems() as $item) {
if ($useManager) {
$obj = $managerClass::$managerGetter($item->getId());
} else {
$obj = new $targetClass($item);
}
if (!is_null($obj)) {
if (is_object($obj)) {
//.........这里部分代码省略.........
示例14: __get
/**
* PHP getter magic method.
* This method is overridden so that AR attributes can be accessed like properties.
* @param string $name property name
* @return mixed property value
* @see getAttribute
*/
public function __get($name)
{
if (property_exists($this, $name)) {
return $this->{$name};
} else {
if (isset($this->_attributes[$name])) {
return $this->_attributes[$name];
} else {
if (isset($this->relations[$name])) {
return $this->relations[$name];
} else {
if (isset($this->relations()[$name])) {
return $this->getRelated($name);
} else {
return parent::__get($name);
}
}
}
}
}
示例15: __get
/**
* Returns a property value, an event handler list or a behavior based on its name.
* Do not call this method. This is a PHP magic method that we override
* to allow using the following syntax to read a property or obtain event handlers:
* <pre>
* $value=$component->propertyName;
* $handlers=$component->eventName;
* </pre>
* @param string $name the property name or event name
* @return mixed the property value, event handlers attached to the event, or the named behavior
* @throws \CException if the property or event is not defined
* @see __set
*/
public function __get($name)
{
if (array_key_exists($name, $this->_attributes)) {
return $this->_attributes[$name];
} else {
return parent::__get($name);
}
}