我想在cakephp中的組件文件中運行查詢,但它顯示致命錯誤,當我在控制器中執行此操作時,它工作得很好,但我想在組件中執行此操作。如何在CakePHP的組件中運行查詢?
function product_check(){
$this->User = ClassRegistry::init('User');
$this->UserNode = ClassRegistry::init('UserNode');
$this->ProductsUserNode = ClassRegistry::init('ProductsUserNode');
$conditionss = array(
# http://book.cakephp.org/2.0/en/models/retrieving-your-data.html
'OR' => array(
array('ProductsUserNode.'. NODE_ID => $this->Auth->user(NODE_ID)),
array('ProductsUserNode.'. NODE_ID => $this->Auth->user(NODE_IDX)),
),
);
$productcheck = $this->User->UserNode
->ProductsUserNode
->find(
'first'
, array(
'conditions' => $conditionss
)
);
$active = $productcheck['ProductsUserNode']['is_active'];
if ($active == "0")
{
$this->Session->setFlash('You Are Deactived For This Product');
$this->redirect(array('controller'=>'events','action'=>'view_dashboard'));
}
}
,但它表明這個錯誤
Fatal Error
Error: Call to a member function user() on a non-object
我該怎麼辦解決這個問題?由於提前
我已經編輯我的答案瞧瞧吧! – sandip
你使用的是什麼蛋糕版本?你不能有1.3和2.x :) – mark
我現在正在使用2.x。 :) – user2046638