Hi, my name is Juan Manuel from Colombia…I do not know much English but I hope you understand me…
Today I was writing a widget that got a record from the DB and everything was fine when run up and left me an error saying ‘PostMoreVisited does not have a method named “getModule” ’, I do not understand why I asked that the widget has a method called “getModule” but then I did was I created this method in the widget as follows:
public function getModule(){}
And it worked!
Why? … this is a mistake of mine or the framework?
Thanks!
Note: This was with version 1.0.7
pestaa
(Pestaa)
August 9, 2009, 9:52am
2
Do you extend your widget from CWidget?
Yes!
My Widget is like next:
class PostMoreVisited extends CWidget
{
public function run()
{
$criteria=new CDbCriteria;
$criteria->order = 'pubDate DESC, visits DESC';
$criteria->limit = 1;
$models=Post::model()->findAll($criteria);
$this->render('PostMoreVisited',array(
'models'=>$models,
));
}
public function getModule(){}
}
pestaa
(Pestaa)
August 11, 2009, 12:17am
4
I know this sounds a bit stupid… but don’t you call $this->getModule() in your view file by any chance?
No, I have in the view only this:
<ul>
<?php foreach($models as $model): ?>
<?php $url = CController::createUrl('post/show',array('id'=>$model->id));?>
<li><?php echo CHtml::link($model->title,$url,array('class'=>'permalink'));?></li>
<?php endforeach; ?>
</ul>
And then, only include the next code to display the widget:
<?php $this->widget('application.components.PostMoreVisited')?>
pestaa
(Pestaa)
August 11, 2009, 7:32am
6
The problem probably comes from the fact you tried to use createUrl as a static method.
In fact, you can only use that via $this->createUrl(). $this refers to the currently active controller.
As you invoked undefined method, __call() probably tried to reach the active module to figure out what you really asked for.
pestaa:
The problem probably comes from the fact you tried to use createUrl as a static method.
In fact, you can only use that via $this->createUrl(). $this refers to the currently active controller.
As you invoked undefined method, __call() probably tried to reach the active module to figure out what you really asked for.
But, if I use "$this->" instead of "CController::" I get an error because the class inherits from CWidget and not CController.
tri
(tri - Tommy Riboe)
August 11, 2009, 2:40pm
8
You can use $this->controller->
Worked!!.. Thanks to "pestaa" and "tri", thank you very much you for your cooperation.
Bye!