2
votes

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

Missing Method in CommentsController 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

2
It seems that there is a problem with the plugin, so I moved to CakeDC comments plugin github.com/CakeDC/commentsBrary

2 Answers

1
votes

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 ?

0
votes

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.