2015-06-02 127 views
0
$player = $this->Players->get($id, [ 
     'contain' => [] 
    ]); 
    $this->set('player', $player); 
    $this->set('_serialize', ['player']); 

如果我將刪除$ this-> set('_ serialize',['player'])比我在我看來沒有任何區別。在cakephp 3.0中設置和序列化的核心區別?

 <h6 class="subheader"><?= __('First Name') ?></h6> 
     <p><?= h($player->first_name) ?></p> 
     <h6 class="subheader"><?= __('Last Name') ?></h6> 
     <p><?= h($player->last_name) ?></p> 
     <h6 class="subheader"><?= __('Email') ?></h6> 
     <p><?= h($player->email) ?></p> 
     <h6 class="subheader"><?= __('Password') ?></h6> 
     <p><?= h($player->password) ?></p> 
     <h6 class="subheader"><?= __('Birthdate') ?></h6> 
     <p><?= h($player->birthdate) ?></p> 
     <h6 class="subheader"><?= __('Mailning Address') ?></h6> 
     <p><?= h($player->mailning_address) ?></p> 
     <h6 class="subheader"><?= __('City') ?></h6> 
     <p><?= h($player->city) ?></p> 
     <h6 class="subheader"><?= __('State') ?></h6> 
     <p><?= h($player->state) ?></p> 
     <h6 class="subheader"><?= __('Country') ?></h6> 

回答

2

的_serialize鍵是一個特殊的視圖變量,表示使用數據視圖時 其它視圖變量(多個)應序列。 如果您不需要在數據被 轉換爲json/xml之前執行任何自定義格式化,則可以跳過爲控制器操作定義模板文件 。 http://book.cakephp.org/3.0/en/views/json-and-xml-views.html#using-data-views-with-the-serialize-key

這對XML和JSON的觀點一個很好的功能,但如果你使用自己的視圖模板幾乎無用。

相關問題