php - Cakephp 加入无法在 Linux 上工作

标签 php mysql cakephp join cakephp-2.0

我有一个模型投资组合,我在其中定义了加入方式

public $belongsTo = array(
        'Category' => array(
            'className' => 'Category',
            'foreignKey' => 'category_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        )
    );

现在当我在 Controller 中使用代码时:

$this->Portfolio->recursive = 0;
        $this->paginate = array(
            'fields' => array('Portfolio.id', 'Portfolio.application_name','Portfolio.category_id','Portfolio.description','Portfolio.screenshots','Portfolio.icon','Portfolio.bg_color_code','Portfolio.created','Category.title','Category.id'),
            'limit' => 10,
            'order' => array(
                'Portfolio.id' => 'asc'
            )
        );

所以它在我的 window 7 上工作正常,但在 linux 服务器上给我错误,例如:

Database Error

Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Category.title' in 'field list'

SQL Query: SELECT `Portfolio`.`id`, `Portfolio`.`application_name`, `Portfolio`.`category_id`, `Portfolio`.`description`, `Portfolio`.`screenshots`, `Portfolio`.`icon`, `Portfolio`.`bg_color_code`, `Portfolio`.`created`, `Category`.`title`, `Category`.`id` FROM `portfolios` AS `Portfolio` WHERE 1 = 1 ORDER BY `Portfolio`.`id` asc LIMIT 10

Notice: If you want to customize this error message, create app/View/Errors/pdo_error.ctp

我的类别模型包含

var $hasMany = array(
        'Portfolio' => array(
            'className' => 'Portfolio',
            'foreignKey' => 'category_id',
        )

    );

我的 table

CREATE TABLE IF NOT EXISTS `categories` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(255) NOT NULL,
  `parent_id` int(11) NOT NULL DEFAULT '0',
  `status` enum('1','2') NOT NULL COMMENT '''1''=active,''2''=inactive',
  PRIMARY KEY (`id`)
) 

我已经在调试结果中测试了它的显示

Included Files
Include Paths
    0/home/reviewpr/public_html/imobdevnew/lib
    2/usr/lib/php
    3/usr/local/lib/php
    4-> /home/reviewpr/public_html/imobdevnew/lib/Cake/
Included Files
    core
    app
        Config
        Controller
        Model
            0APP/Model/AppModel.php
        Other
            0APP/webroot/index.php
    plugins

它在本地显示的位置

Included Files
Include Paths
    0C
    1\wamp\www\imobdevnew\lib;.;C
    2\php\pear
    3-> C:\wamp\www\imobdevnew\lib\Cake\
Included Files
    core
    app
        Other
            0APP/webroot\index.php
            1APP/Config\core.php
            2APP/Config\bootstrap.php
            3APP/Config\config.php
            4APP/Config\routes.php
            5APP/Controller\PortfoliosController.php
            6APP/Controller\AppController.php
            7APP/Model\portfolio.php
            8APP/Model\AppModel.php
            9APP/Config\database.php
            10APP/Model\category.php
    plugins

这意味着它没有加载模型。

请帮帮我...

最佳答案

Linux 区分大小写

不祥地出现在您的 Windows 安装的包含文件中的是这些文件:

7APP/Model\portfolio.php
...
10APP/Model\category.php

这些文件大小写错误 - 所以在 linux 上它们不包含在内,相反你的模型将是 AppModel 实例。

这将是问题的直接原因,因为没有加载模型文件,也不会有模型关联。

要解决此问题,只需确保您的所有文件都遵循约定 - 这意味着:

APP/Model/portfolio.php -> APP/Model/Portfolio.php
APP/Model/category.php -> APP/Model/Category.php

文件名和其他约定在 the documentation 中进行了总结.

关于php - Cakephp 加入无法在 Linux 上工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17103430/

相关文章:

php - 如何从 PayPal 获取用于自适应支付的 Pay API key

javascript - 为什么动态添加的字段不通过单击删除按钮删除?

php - mysqli 图像 blob 插入不工作

php - 如何在 laravel 控制台命令中显示异常跟踪?

mysql - 我如何在 cakephp 中获取用户与所有其他用户的最后消息

mysql - 蛋糕 3 : column of type JSON stores a NULL as string "null"

php - 缺少 SSL 证书?

MYSQL巨大SQL文件插入| MyISAM 插入速度突然变慢(奇怪的问题)

插入后和更新后的 MySQL 触发器

java - 因缺少数据库连接而挂起