因此,我有两个蛋糕应用程序(一个是网站前端,另一个是我的管理员仪表板),我的所有模型都在我的管理应用程序上声明,所以我将它们加载到我的网站应用:Cakephp无法找到我的模型
App::build(
array('Model' => array(
Configure::read('Extranet.path') . 'app/Model')
), App::RESET);
这似乎是工作的罚款,因为当我这样做:
var_dump(App::objects('Model'), false);
我得到:
array(19) { [0]=> string(8) "AppModel" [1]=> string(6) "Banner" [2]=> string(5) "Brand" [3]=> string(8) "Category" [4]=> string(12) "CategorySize" [5]=> string(5) "Color" [6]=> string(8) "Customer" [7]=> string(11) "EntityImage" [8]=> string(6) "Gender" [9]=> string(5) "Group" [10]=> string(5) "Image" [11]=> string(10) "Newsletter" [12]=> string(10) "Permission" [13]=> string(7) "Product" [14]=> string(12) "ProductImage" [15]=> string(4) "Size" [16]=> string(6) "Status" [17]=> string(11) "UsageStatus" [18]=> string(4) "User" } bool(false)
貌似蛋糕为r ecognizing我的模型,但是当我尝试调用的具体方法:
<?php
class PagesController extends AppController {
public $helpers = array('Html', 'Form');
public $components = array('Paginator', 'Permission');
public $uses = array('User');
public function index() {
var_dump(App::objects('Model'), false);
$this->User->test();
$this->set('page', 'home');
}
}
我得到的是:
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 'test' at line 1
据我searchs,当蛋糕试图精确地执行一个SQL查询,如方法名称,这是因为它没有找到模型类(但它在转储App :: objects时发现它!)。
我没有找到任何地方,我应该怎么去找出为什么不能cakephp加载我的模型(并且它更加困扰我知道蛋糕把它隐藏起来而不是尖叫在我的脸上)。
我该如何继续?
编辑: 这是CakePHP的文档中的一段文字:
CakePHP会动态地为你创建一个模型对象,如果不能找到在/ app /型号对应的文件。这也意味着如果您的模型文件没有正确命名(例如,如果它命名为ingredient.php或Ingredients.php而不是Ingredient.php),CakePHP将使用AppModel的实例而不是您的模型文件(其中CakePHP假定缺失)。如果您尝试使用您在模型中定义的方法或附加到模型的行为,并且您收到的SQL错误是您调用的方法的名称,那么肯定会发现CakePHP找不到您的模型,您需要检查文件名,应用程序缓存或两者。
然而,我的文件名是否正确User.php
,我的缓存文件夹完全是空的,我有Configure::write('Cache.disable', true);
我bootstrap.php中。
任何方向来找出至少哪个文件是蛋糕PHP试图加载将是很好的。谢谢。
你的用户模型中有test()方法吗? – SkarXa 2014-10-06 19:03:09
是的,我确实(我可以在我的管理仪表板应用程序中使用它) – 2014-10-06 19:05:00