gpt4 book ai didi

php - 如何在cakephp的组件中运行查询?

转载 作者:行者123 更新时间:2023-12-04 18:10:21 25 4
gpt4 key购买 nike

我想在 cakephp 的组件文件中运行查询,但它显示 fatal error ,当我在 Controller 中执行此操作时它工作得很好,但我想在组件中执行。

 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

我该如何解决这个问题?提前致谢

最佳答案

我认为您没有指定您的组件使用 Auth 组件。您可以使用以下代码片段完成此操作:

public $components = array('Auth');

另见 Using other Components in your Component

关于php - 如何在cakephp的组件中运行查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14745742/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com