gpt4 book ai didi

mysql - CakePHP 2.4.2 为什么 Cake 使用模型名称作为 SQL 查询?

转载 作者:行者123 更新时间:2023-11-29 08:18:56 24 4
gpt4 key购买 nike

我有一个新鲜的 git repo CakePHP 应用程序。我刚刚创建了一个新模型(Ingests)来跟踪我们的系统引入了哪些数据。我想制作函数 start() 和 end(),但 end 受到保护,所以我切换到 begin() 和 finish()。

无论我做什么,CakePHP 都会尝试将模型函数名称逐字执行为 SQL 查询。我本周一直在这个应用程序中开发另一个模型,但根本没有这个问题。今天创建一个新表/模型就是问题出现的时候。

IngestsController.php

public function test(){


$this->autoRender = false;

//$result = $this->Ingest->finish();
$result = $this->Ingest->xyz();

debug($result);

}

Ingests.php 模型

public function finish($id){

return 'giraffe';

}

public function xyz(){

return 'abc';

}

输出:

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 'xyz' at line 1

SQL Query: xyz

我尝试了 xyz(),因为 xyz() 不可能是 protected /不允许的函数名称......但显然它与 finish() 一样糟糕。如果我运行 finish() 函数,我会得到相同的输出...“SQL 查询:完成”

最佳答案

检查您的文件名,您的文件名模型的名称应该是 Ingest.php 而不是 Ingests.php 还要检查您的类声明:

<?php
App::uses('AppModel', 'Model');

class Ingest extends AppModel { //Make sure the model name is singular

public function finish($id){

return 'giraffe';

}

public function xyz(){

return 'abc';

}
}

关于mysql - CakePHP 2.4.2 为什么 Cake 使用模型名称作为 SQL 查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19984134/

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