3

向模型调用函数时出现此错误。

Database Error

Error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'singleBlockWeekly' at line 1

SQL Query: singleBlockWeekly 

这是我的控制器

class BlackoutController extends CalendarAppController
{
    var $uses = array('Studio','Blackout','BlackoutRepeatTypeDetails','Calendar.Event');
    var $components = array('Accesscontrol','RequestHandler');
    function event_checker()
    {
        $start_date = $this->request->data['start_date'];
        $end_date = $this->request->data['end_date'];
        $endsOn = $this->request->data['endsOn'];
        $repeatType = $this->request->data['repeatType'];
        $blockType = $this->request->data['blockType'];
        $frequency = $this->request->data['freq'];
        $repeatDays = $this->request->data['repeatDays'];

        #single type 
        if($blockType == "single"){
            if($repeatType == "weekly"){
                $dates = $this->Blackout->singleBlockWeekly($start_date,$endsOn,$repeatDays,$frequency);
                debug($dates);
                die;
            }
        }
     }
}

这是我的Model

class Blackout extends CalendarAppModel
{
   var $name = 'Blackout';
   var $useTable = false;
   function singleBlockWeekly($startDate,$endDate,$repeatEvery = array(),$freq)
   {
     /*my code here...brevity...*/
   }
}

所以我在这里只是调用停电模型中的 singleBlockWeekly 函数。我想知道为什么即使singleBlockWeekly函数上没有任何与 SQL 相关的代码,我也会收到奇怪的 SQL 错误?

对你的帮助表示感谢!谢谢!:)

4

2 回答 2

2

我假设这是一个插件?您不能只将其包含为“Blackout”,您需要使用记录在案的插件语法“Calendar.Blackout”。否则,您将加载一个 AppModel 实例,该实例当然没有此方法。

如果您调试了模型实例,您可能已经自己发现了这一点:

debug($this->Blackout);

此 SQL 错误始终表明模型包含语句的滥用。

于 2013-06-18T06:27:46.287 回答
1

加载模型时出现问题,所以试试这个

$this->loadModel('Blackout');
$dates = $this->Blackout->singleBlockWeekly($start_date,$endsOn,$repeatDays,$frequency);
于 2013-06-18T06:37:59.093 回答