CakePHP模型缓存函数名称



我非常熟悉CakePHP 2.0,但这是我还没有见过的。

我的模型正在尝试运行本身不存在的函数。这种情况只在Linux环境中发生,我仔细检查了文件名是否正确。我以前遇到过文件名不匹配的情况。在Windows环境中,代码运行良好。

背景。我早期的函数名为"sql_version_xx",直到今天,版本33开始失败,它们才正常工作。33岁以下的所有功能都很有魅力。33和以上所有人都死于这个神秘的错误。我想这是个愚蠢的打字错误,但我真的找不出来。即使我重命名了函数,错误仍然是一样的(我认为这与CakePHP风格有关,将SqlVersion33转换为sql_version_33,反之亦然)。重命名没有帮助。

代码是为管理软件数据库更新而构建的,我们在这个阶段有很多:D

有人能认出这里的拼写错误吗?

以下是案例的详细信息:

  • 型号为Installer.php
  • 控制器是InstallersController.php

以下是错误:

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 'sql_version_33' at line 1
SQL Query: sql_version_33
Notice: If you want to customize this error message, create app/View/Errors/pdo_error.ctp
Stack Trace
CORE/Cake/Model/Datasource/DboSource.php line 460 → PDOStatement->execute(array)
CORE/Cake/Model/Datasource/DboSource.php line 426 → DboSource->_execute(string, array)
CORE/Cake/Model/Datasource/DboSource.php line 666 → DboSource->execute(string, array, array)
CORE/Cake/Model/Datasource/DboSource.php line 611 → DboSource->fetchAll(string, array, array)
CORE/Cake/Model/Model.php line 799 → DboSource->query(string, array, Installer)
APP/Model/Installer.php line 16 → Model->__call(string, array)
APP/Model/Installer.php line 16 → Installer->sql_version_33()
APP/Controller/InstallersController.php line 35 → Installer->Install(string)
[internal function] → InstallersController->install(string)
CORE/Cake/Controller/Controller.php line 490 → ReflectionMethod->invokeArgs(InstallersController, array)
CORE/Cake/Routing/Dispatcher.php line 187 → Controller->invokeAction(CakeRequest)
CORE/Cake/Routing/Dispatcher.php line 162 → Dispatcher->_invoke(InstallersController, CakeRequest, CakeResponse)
APP/webroot/index.php line 92 → Dispatcher->dispatch(CakeRequest, CakeResponse)

以下是模型的代码片段:

<?php
App::uses('AppModel', 'Model');
App::import('Model', 'CContact');
class Installer extends AppModel {
public $useTable = 'c_event';
private $sql = array();
private $sql_indexes = array();
private $messages = array();

public function Install($version){
$this->sql = array();
$sql_function = 'sqlversion' . $version;
if(method_exists('Installer', $sql_function)) $this->$sql_function();
$string = '';
foreach($this->sql as $sql)
$string .= $sql . ';';
$dataSource = $this->getDataSource();
$dataSource->begin();
try{
if(strlen($string)>0)
$this->SqlQuery($string);
} catch(Exception $e){
$dataSource->rollback();
return array('exception' => $e->getMessage(), 'sql' => $this->sql);
}
$dataSource->commit();
}

下面是同一型号的两个功能:

public function sqlversion34(){
if(!array_key_exists('delay', $this->desc_table('k4_drafts')))
$this->sql[] = "ALTER TABLE k4_drafts ADD delay DATE NULL DEFAULT NULL";
if(!array_key_exists('remark', $this->desc_table('k4_drafts')))
$this->sql[] = "ALTER TABLE k4_drafts ADD remark DATE NULL DEFAULT NULL";
if(!array_key_exists('payday', $this->desc_table('k4_drafts')))
$this->sql[] = "ALTER TABLE k4_drafts ADD payday DATE NULL DEFAULT NULL";
}
public function sqlversion33(){
if(array_key_exists('payday', $this->desc_table('k4_drafts')))
$this->sql[] = "ALTER TABLE k4_drafts DROP payday";
}
public function sqlversion32(){
$this->sql[] = "ALTER TABLE k4_row_pen_intr CHANGE create_stamp create_stamp TIMESTAMP on update CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP";
}

正如你所看到的。没有函数调用函数"sql_version_33",但我仍然收到此错误消息。

编辑:问题已解决

从堆栈跟踪来看,您的问题就在这里:

APP/Model/Installer.php第16行→安装程序->sql_version_33()

看看/App/Model/Installer的第16行,看看这个调用是什么。也许可以尝试将其更改为sqlversion33()。

最新更新