我試圖訪問我的模型中的數據以獲取我的控制器方法。在CakePHP 2.0中訪問控制器中的模型數據
對於初學者這兩者之間有什麼區別?
$post = $this->Post->find('first',array('conditions'=>array('Post.id'=>$id)));
$this->set(compact('post'));
和
$this->Post->id = $id;
$this->data = $this->Post->read();
因爲我想比較USER_ID針對登錄用戶像這樣一個帖子:
if($this->Post->user_id != $this->Auth->user('id'))
,但它不工作如預期的那樣(它總是返回false)......這兩個代碼塊之間有什麼區別,爲什麼上面的代碼行不正常?看到
記住在你的控制器打電話驗證的:var $ =組件陣列(「驗證」); – 2012-01-27 08:20:43
這個問題是不是與驗證!這是'$ this-> Post-> user_id'的問題,即使是有效的代碼?在cakePhp 2.0 de代碼中, – Cameron 2012-01-27 09:36:00
是:$ this-> request-> data = $ this-> Post-> read(null,$ id); – 2012-01-27 10:15:37