CakePHP retrieving data from model using find(). D

2019-02-19 05:58发布

I have the same exact code on my production and development servers but I seem to get different array keys when using find('first') to retrieve data.

Development:

Array
(
    [Page] => Array
        (
            [title] => Welcome!
            [keywords] => keyword 1 keyword 2 keyword 3
        )

)

Production:

 Array
(
    [0] => Array
        (
            [title] => Welcome!
            [keywords] => keyword 1 keyword 2 keyword 3
        )

)

Code in AppController:

//get page title and keywords
        $currentPage = $this->Page->find('first', 
            array(
                'conditions' => array('Page.name' => $this->params['controller']),
                'fields' => array('Page.title', 'Page.keywords')
            ));


        pr($currentPage);

2条回答
Evening l夕情丶
2楼-- · 2019-02-19 06:53

I remember this one... :P I had the same problem before

It's caused either by the php version or the mysql version. Check if your server passes the minimum requirements for your cake version

requirements for cakephp2.0

requirements for cakephp1.3

you can check them using a phpinfo();

Hope this helps

查看更多
SAY GOODBYE
3楼-- · 2019-02-19 07:00

use $this->set(compact('currentPage',$currentPage));

查看更多
登录 后发表回答