开发者

CakePHP - query is name of model function [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 9 years ago.

Controller:

<?php
class VideosController extends ForumAppController {

    /**
     * Controller Name
     * @access public
     * @var string
     */
    public $name = 'Videos';


    public function index() {
        $videos = $this->Video->getVideos();
        $this->set('videos', $videos);
    }

    public function beforeFilter() {    
        parent::beforeFilter();

        $this->Auth->allow('*');

        if (isset($this->params['admin'])) {
            $this->Toolbar->verifyAdmin();
            $this->layout = 'admin';
        }       
      开发者_开发百科  $this->Security->validatePost = false;
        $this->set('menuTab', 'videos');
    }

}

?>

Model:

<?php
class Video extends ForumAppModel {

    public $name = 'Video';

    function getVideos() {

        $vids = $this->find('all', array (
            'order'     =>  array('Video.id DESC')
        ));

      return $vids;
    }

}

?>

I get an error:

Notice (8): Undefined property: VideosController::$Video [CORE/plugins/forum/controllers/videos_controller.php, line 13]

If I do

$this->loadModel('video');

I get an error:

Warning (512): SQL Error: 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 'getVideos' at line 1 [CORE/cake/libs/model/datasources/dbo_source.php, line 549]
**Query: getVideos** 

Any ideas what might be causing this?


You code appears to be correct but it seems like CakePHP isn't trying to load the model from the right place. You can specify the model to load using the $uses variable in your controller.

Because you're using a plugin, you need to add the name of the plugin in front of the model.

$uses = array('Forum.Video');

CakePHP should handle this on it's own but some older version of CakePHP had a bug that prevented this from working properly. It appears to be fixed in 1.3.10.

For more details about the $uses variable, see http://book.cakephp.org/view/961/components-helpers-and-uses.


The $name variable is controller name, not model name controller uses,

try this

$uses = "Videos"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜