开发者

CakePHP comments plugin problem

开发者 https://www.devze.com 2023-03-17 22:58 出处:网络
Hi I\'m trying to use the CakePHP comments plugin found here it gives me the following error Missing Method in Co开发者_如何学运维mmentsController

Hi I'm trying to use the CakePHP comments plugin found here it gives me the following error

Missing Method in Co开发者_如何学运维mmentsController Error: The action index is not defined in controller CommentsController Error: Create CommentsController::index() in file: app\controllers\comments_controller.php.

So far I've created the comments table, added it to the plugins and added the following code to Test controller as I want to add comments in 'take' action:

public function beforeFilter() {

parent::beforeFilter();     
$this->passedArgs['comment_view_type'] = 'flat'; 
$this->passedArgs['actionNames'] = 'take';

}

function take($id) {

$this->Test->recursive = 2;
$this->set('test', $this->Test->read(null, $id)); 

}

I added the route

Router::connect('/comments/:action/*',array('plugin' => 'comments','controller' => 'comments'));

I'm just wondering if anyone has used this plugin before and can help me out?

thanks,

Brary


I haven't used that plugin, but the error is very common in Cake:

Cake is looking for the index function as that is the default or home function for that or any controller. In essence cake is failing because it is try to route to you a page (I am assuming /comments) through the function called index() inside the comments controller. It is core Cake MVC routing functionality.

If you want that page to work, you need to add:

function index(){
...controller code...
}

to comments_controller.php. However, you will also need to add a index.ctp file to /app/views/comments otherwise cake will give you the missing view error.

What happens at the url /comments/take ?


Whoa my bad, I didn't see you're not using the official CakeDC comments plugin, which I'd recommend using over the 2009 one you are.

0

精彩评论

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