Comment and its behaviors do not have a method or closure named "getUrl".

Hi,

I’m currently following the blog tutorial (provided in the Yii documentation, http://www.yiiframework.com/doc/blog/), and I came across this error:

Comment and its behaviors do not have a method or closure named "getUrl".

Below is some of the Stack Trace:

#0 C:\xampp\htdocs\yii\framework\db\ar\CActiveRecord.php(227): CComponent->__call("getUrl", array(Post))

#1 C:\xampp\htdocs\blog\protected\views\post\_comments.php(3): CActiveRecord->__call("getUrl", array(Post))




<?php foreach($comments as $comment): ?>

1 <?php foreach($comments as $comment): ?>

2 <div class="comment" id="c<?php echo $comment->id; ?>">

3     <?php echo CHtml::link("#{$comment->id}", $comment->getUrl($post), array(

4         'class'=>'cid',

5         'title'=>'Permalink to this comment',

6     )); ?>

7     <div class="author">

8         <?php echo $comment->authorLink; ?> says:



[size="7"]…[/size]

#5 C:\xampp\htdocs\blog\protected\views\post\view.php(20): CController->renderPartial("_comments", array("post" => Post, "comments" => array(Comment)))




15         <?php echo $model->commentCount >= 1 ? $model->commentCount. ' comments' : '1 comment'; ?>

16     </h3>

17 

18     <?php $this->renderPartial('_comments', array(

19         'post'=>$model,

20         'comments'=>$model->comments,

21     )); ?>

22     <?php endif; ?>

23 

24     <h3>Leave a comment</h3>

25 



I’m new to Yii, and I tried defining actionGetUrl in the PostController, but nothing changed. Can someone please help me? I’m still in the process of understanding this framework. Thanks!

Oops, I just noticed I posted this in the Yii 2.0 forum… I should’ve posted this in Yii 1.1.x. My bad.

Update: now working. I added a getUrl method in the Comment class (code snippet provided below).




public function getUrl()

{

	return Yii::app()->createUrl('post/view', array(

		'id'=>$this->id,

		'title'=>$this->title,

	));

}



Special thanks to [color="#FF0000"]renic[/color] for replying to my concern in the live chat. The Yii community is nice.