Access Model In Widget

Hi,

i like to use an model insight an widget.

For this, I initialize the model, filling an session variable into the model attributes in oder to render an view.

The view is located insight the widget folder under views/_part_SearchForm.php.

My widget-code lookes like that:


class SearchFormWidget extends CWidget

{

   public function init()

    {

       //

    }

 

    public function run()

    {

        

        $model = new SearchSets();  //init  model

        $model->setAttributes(Yii::app()->user->solrSet); //fill attributes from session variable

        $this->render('_part_SearchForm', array('model'=>$model)); //render the 

    }

}

Running this code, i get an CException: SearchFormWidget and Behavior does not have an scope "getModule".

What’s happend here and is there a way to solve that problem in order to use models insight an widget?

Thank you,

rall0r.

The model is fine, the error is somewhere else.

I think you should run parent::init() from your init(), or remove it at all.

Somewhere in widget "SearchFormWidget" called method "getModule".

Please show file "_part_SearchForm" and where you included widget.

>The model is fine, the error is somewhere else.

Okay, that was the first important information for me. Thank you.

>Please show file "_part_SearchForm" and where you included widget.

yeah… it looks like, the error comes from here.

I found, that CController::createUrl seams to generate this error.

And it looks like, the error occurs, if I use an object/class from protected/components/myStuff.php

Is there a way to use the methods and classes??

//Edit:

I found that http://stackoverflow.com/questions/2597545/widget-within-module-in-yii

This means, i have to use the methods in th followig way:

Yii::app()->getModule(‘myStuff::myMethod()’);

Yii::app()->getModule(‘CController::createUrl’);

Could this be an performance issue, if i have to use CController::createUrl multiple times?

CWidget has a property ‘controller’, you can use it.


Yii::app()->controller->createUrl('url');

okay.

so it lookes like, i have 3 ways to use (for example) createUrl:

Yii::app()->getModule(‘CController::createUrl’);

$this->controller->createUrl(…

Yii::app()->createUrl(…

Right? I don’t know, if there is an major different and what is better and faster?

I always call so

of widget


Yii::app()->controller->createUrl()

of view


$this->createUrl()

The first construction never didn’t use.

Second and third the same because they refer one object.