cakephp包含不在实时网站上工作

时间:2014-01-02 00:29:17

标签: cakephp model cakephp-appmodel

我的应用程序在我的本地服务器上工作正常,我不得不更改.htaccess文件,以便cakephp应用程序网站可以在godaddy托管上工作,但现在我发现某些信息不是从现场的表中检索到的网站很奇怪,因为在我的本地应用程序中检索到相同的信息...我已经失去了几个小时寻找原因,但还没有找到可能的解释......

在这个特定的视图中,我应该得到所有产品价格(仅适用于本地):

public function index() {
    $options = array('contain' => 'ProductPrice');
    $this->set('products', $this->Product->find('all', $options));
}

必要的模型在控制器上方加载:

public $uses = array('ProductPrice', 'Product', 'MenuSection');

在视图中我应该得到类似的东西:(在我的本地应用程序中发生)

products(array)
    0(array)
        Product(array)
        ProductPrice(array)
    1(array)
        Product(array)
        ProductPrice(array)
    (and so on...)

但我得到的是:(在我的直播应用中发生)

products(array)
    0(array)
        Product(array)
    1(array)
        Product(array)
    (but no ProductPrice arrays...)

这些是表结构:

CREATE TABLE `product_prices` (
  `id` tinyint(9) unsigned NOT NULL AUTO_INCREMENT,
  `price` float(6,2) DEFAULT NULL,
  `product_id` varchar(36) DEFAULT NULL,
  `created` datetime DEFAULT NULL,
  `modified` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=181 DEFAULT CHARSET=utf8;

CREATE TABLE `products` (
  `id` int(9) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(100) DEFAULT NULL,
  `description` text,
  `menu_nr` int(9) DEFAULT NULL,
  `menu_section_id` int(9) DEFAULT NULL,
  `created` datetime DEFAULT NULL,
  `modified` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=96 DEFAULT CHARSET=utf8;

这些是模型:

class ProductPrice extends AppModel {
        public $name = 'ProductPrice';
        public $useTable = 'product_prices';
        public $actsAs = array('Containable');
        public $belongsTo = array('Product');
        public $validate = array(
            'product_id' => array(
                'rule' => 'notEmpty',
                'message' => 'This is a required field and cannot be left empty.'
            ),
        );
}
class Product extends AppModel {
    public $name = 'Product';
    public $actsAs = array('Containable');
    public $hasMany = array(
        'ProductPrice'
    );
    public $belongsTo = array(
        'MenuSection',
    );
    public $validate = array(
        'name' => array(
            'rule-empty' => array(
                'rule' => 'notEmpty',
                'message' => 'This is a required field and cannot be left empty.'
            ),
            'rule-unique' => array(
                'rule' => 'isUnique',
                'message' => 'There is already one product with that name.'
            ),
        ),
        'menu_nr' => array(
            'rule' => 'isUnique',
            'message' => 'There is already one product with that Menu Item Nr.'
        )
    );
}

有人能帮我找到原因吗?我还应该在哪里寻找?任何提示或最佳实践建议也是受欢迎的,谢谢。

1 个答案:

答案 0 :(得分:0)

我终于明白了......毕竟这是一个简单的问题。我的模型名称被称为'product.php'和'product_prices.php',因为我遵循CakePHP博客示例,但是一旦我将它们更改为'Product.php'和'ProductPrice.php'(依此类推......)就开始了工作!我之前想过这个,但忘记了在混乱的中间尝试它。干杯试图帮助