gpt4 book ai didi

php - CakePHP 在 Controller 中时调用模型中的函数

转载 作者:搜寻专家 更新时间:2023-10-31 20:43:20 26 4
gpt4 key购买 nike

我在调用模型函数时遇到此错误。

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

这是我的 Controller

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;
}
}
}
}

这是我的模型

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 错误?

非常感谢您的帮助!谢谢! :)

最佳答案

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

如果您调试了模型实例,您可能会自己发现:

debug($this->Blackout);

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

关于php - CakePHP 在 Controller 中时调用模型中的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17161602/

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