My app works fine on my local server and I had to change the .htaccess files so that the cakephp app website would work on godaddy hosting, but now I found that some of the information is not retrieved from the tables in the live website which is weird because the same information is retrieved in my local app... I've lost hours searching for the cause but haven't found a possible explanation yet...

On this particular view I should get all the product prices doing this (only works locally):

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

The necessary models are loaded above in the controller with:

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

In the view I should get something like: (which happens in my local app)

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

but what I'm getting is: (which happens in my live app)

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

These are the table structures:

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;

These are the models:

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.'
        )
    );
}

Could anyone help me find the cause? Where else should I look for? Any hints or best practice suggestions are welcome too, thanks.

有帮助吗?

解决方案

I finally figured it out... it was a simple problem after all. My model names were called 'product.php' and 'product_prices.php' because I followed CakePHP blog example, but once I changed them to 'Product.php' and 'ProductPrice.php' (and so on...) they started working! I thought about this before but forgot to actually try it while in the middle of the mess. Cheers for trying to help

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top