0
當在索引視圖上單擊'編輯'按鈕時,數據首先被提交給PostsController Edit操作。由於在該動作中未調用「設置」功能,因此edit.ctp視圖如何呈現並且編輯後的數據是否回到了編輯動作?CakePHP博客教程編輯帖子 - 提交的數據如何提供給編輯操作?
當在索引視圖上單擊'編輯'按鈕時,數據首先被提交給PostsController Edit操作。由於在該動作中未調用「設置」功能,因此edit.ctp視圖如何呈現並且編輯後的數據是否回到了編輯動作?CakePHP博客教程編輯帖子 - 提交的數據如何提供給編輯操作?
您應該從控制器中粘貼代碼,以便人們可以確切地看到您在說什麼。
假設你有一個非常標準的編輯方法,它應該包含一條線是這樣的:
$this->request->data = $this->Post->read(null, $id)
因此,$this->request->data
設置。蛋糕確保整個$this->request
在視圖中可用。在View超類中,有一個名爲$_passedVars
的數組,其中包括request
。在視圖的__construct
中,它將控制器中$_passedVars
中指定的每個變量複製到視圖中。
如果你想看到的細節,請/lib/Cake/View/View.php
,特別是$_passedVars
變量,__construct
方法的前幾行:
/**
* List of variables to collect from the associated controller.
*
* @var array
*/
protected $_passedVars = array(
'viewVars', 'autoLayout', 'ext', 'helpers', 'view', 'layout', 'name', 'theme',
'layoutPath', 'viewPath', 'request', 'plugin', 'passedArgs', 'cacheAction'
);
和
/**
* Constructor
*
* @param Controller $controller A controller object to pull View::_passedVars from.
*/
public function __construct(Controller $controller = null) {
if (is_object($controller)) {
$count = count($this->_passedVars);
for ($j = 0; $j < $count; $j++) {
$var = $this->_passedVars[$j];
$this->{$var} = $controller->{$var};
}
$this->_eventManager = $controller->getEventManager();
}
if (empty($this->request) && !($this->request = Router::getRequest(true))) {
$this->request = new CakeRequest(null, false);
$this->request->base = '';
$this->request->here = $this->request->webroot = '/';
}
if (is_object($controller) && isset($controller->response)) {
$this->response = $controller->response;
} else {
$this->response = new CakeResponse();
}
$this->Helpers = new HelperCollection($this);
$this->Blocks = new ViewBlock();
$this->loadHelpers();
parent::__construct();
}
使用調試器/做追蹤。 – 2014-10-12 07:59:40