setAttr() 공개 메소드

修改器 设置数据对象值
public setAttr ( string $name, mixed $value, array $data = [] )
$name string 属性名
$value mixed 属性值
$data array 数据
예제 #1
0
파일: Relation.php 프로젝트: GDdark/cici
 /**
  * 一对一 关联模型预查询拼装
  * @access public
  * @param string    $model 模型名称
  * @param string    $relation 关联名
  * @param Model     $result 模型对象实例
  * @return void
  */
 protected function match($model, $relation, &$result)
 {
     // 重新组装模型数据
     foreach ($result->toArray() as $key => $val) {
         if (strpos($key, '__')) {
             list($name, $attr) = explode('__', $key, 2);
             if ($name == $relation) {
                 $list[$name][$attr] = $val;
                 unset($result->{$key});
             }
         }
     }
     if (!isset($list[$relation])) {
         // 设置关联模型属性
         $list[$relation] = [];
     }
     $result->setAttr($relation, (new $model($list[$relation]))->isUpdate(true));
 }