【问题标题】:Cakephp: Why delete custom query is not working in app_controller?Cakephp:为什么删除自定义查询在 app_controller 中不起作用?
【发布时间】:2011-11-04 06:22:17
【问题描述】:

我在 aap_controller 的 beforeFilter 中写了下面的代码。

$this->query('delete * from suggest_debate_tags where suggest_debate_id = 0');

错误:

Call to undefined method UsersController::query()

【问题讨论】:

    标签: cakephp cakephp-1.3 cakephp-1.2


    【解决方案1】:

    AppController 类扩展了作为控制器基础的控制器类。 query 是模型的一部分,因此 $this->query() 将不起作用。您需要将 query() 调用放入模型并从 AppController 调用模型。

    【讨论】:

      【解决方案2】:

      终于找到解决办法了

      我在 aap_controller 的 beforeFilter 中写了下面的代码。

      App::import('Model','SuggestDebateTag');
      
      $cnt_tag_arr = $this->SuggestDebateTag->find('count',array ( "SuggestDebateTag.suggest_debate_id" => 0));
      
      if($cnt_tag_arr > 0)
      {
      
              $conditions = array ( "SuggestDebateTag.suggest_debate_id" => 0);
              $this->SuggestDebateTag->deleteAll($conditions);
      
      }
      

      我在 users_controller.php 中编写以下代码

      var $uses = array('SuggestDebateTag');
      

      它工作正常。

      【讨论】:

      • 您实际上是在清除suggest_debat_tags每次收到请求时。你确定要这样做吗?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-07
      相关资源
      最近更新 更多