CakePHP评论插件问题

时间:2011-07-05 14:18:59

标签: php cakephp plugins comments

您好我正在尝试使用找到here的CakePHP评论插件,它会给我以下错误

  

CommentsController中缺少方法   错误:控制器CommentsController中未定义操作索引   错误:在中创建CommentsController :: index()   file:app \ controllers \ comments_controller.php。

到目前为止,我已经创建了注释表,将其添加到插件中并将以下代码添加到Test控制器中,因为我想在“take”操作中添加注释:

  

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)); 
     

}

我添加了路线

  

路由器::连接( '/评论/:动作/ *',阵列( '插件'   => 'comments','controller'=> '意见'));

我只是想知道是否有人之前使用过此插件并可以帮助我?

感谢,

Brary

2 个答案:

答案 0 :(得分:1)

我没有使用过该插件,但错误在Cake中很常见:

Cake正在寻找索引函数,因为它是该控件或任何控制器的默认函数或home函数。实质上蛋糕失败了,因为它试图通过注释控制器中名为index()的函数路由到您的页面(我假设/注释)。它是核心Cake MVC路由功能。

如果您希望该页面有效,则需要添加:

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

到comments_controller.php。但是,您还需要将一个index.ctp文件添加到/ app / views / comments中,否则cake将为您提供缺少的视图错误。

url / comments / take会发生什么?

答案 1 :(得分:0)

我的不好,我没有看到你没有使用官方的CakeDC comments plugin,我建议你使用这个{{3}}。