<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                #### 創建數據對象之:setAttr方法 * * * * * 1. 作用:如果數據對象中已存在指定數據,則更新;如果不存在,則創建。 setAttr()方法也叫修改器 2. setAttr()源碼: ~~~ /** * 修改器 設置數據對象值 * @access public * @param string $name 屬性名 * @param mixed $value 屬性值 * @param array $data 數據 * @return $this */ public function setAttr($name, $value, $data = []) { if (is_null($value) && $this->autoWriteTimestamp && in_array($name, [$this->createTime, $this->updateTime])) { // 自動寫入的時間戳字段 $value = $this->autoWriteTimestamp($name); } else { // 檢測修改器 $method = 'set' . Loader::parseName($name, 1) . 'Attr'; if (method_exists($this, $method)) { $value = $this->$method($value, array_merge($data, $this->data)); } elseif (isset($this->type[$name])) { // 類型轉換 $value = $this->writeTransform($value, $this->type[$name]); } } // 標記字段更改 if (!isset($this->data[$name]) || ($this->data[$name] != $value && !in_array($name, $this->change))) { $this->change[] = $name; } // 設置數據對象屬性 $this->data[$name] = $value; return $this; } ~~~ 3.setAttr()范例 ~~~ <?php namespace app\index\controller; use app\index\model\Staff; class Index { public function index(){ //1.創建數據模型對象 $model = new Staff(); //2.setAttr()方法操作數據對象 //3.如屬性不存在,則創建該屬性 $model->setAttr('id',10); $model->setAttr('name','Jack'); $model->setAttr('age',20); //4.如屬性已存在,則更新 $model->setAttr('id',11); $model->setAttr('name','Jackee'); $model->setAttr('age',21); //5.查看$model對象 dump($model); } } ~~~ 對象輸出 ~~~ object(app\index\model\Staff)#5 (28) { //這里略去與本例無關的屬性 ······ ["data":protected] => array(3) { ["id"] => int(11) ["name"] => string(4) "Jackee" ["age"] => int(21) } //這里略去與本例無關的屬性 ······ } ~~~ 4.總結 setAttr( )方法,實際開發中并不常用,但在Model類源碼中,卻隨處可見它的身影。該方法不僅可以創建數據對象,還可以更新數據對象。但是該方法只能一個個逐個處理數據,多個數據需要同時處理,就必須多次調用才可以實現。 * * * * * http://www.hmoore.net/ldkt/tp5_model/236655
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看