Assuming that the model that you are querying is within your module, there are 3 workarounds.
One
What you can do is define your renderPageLinks()
function in the QuickDialModule.php file, i.e inside the QuickDialModule class. Then you can use it like this:
Yii::app()->getModule('QuickDial')->renderPageLinks();
You have to write this function inside your QuickDialModule class :
Class QuickDialModule extends CWebModule{
public function init(){
// ... code ...
}
// ... code ... other functions
public function renderPageLinks(){
// ... do whatever you were doing inside the function ...
}
}
Edit:
Controllers are instantiated by yii only when the application receives url requests from the user.
Two
You have another work around by declaring your function static
. But then you'll have to import the php file that has the class that has the function, into the yii autoloading array in the main.php config file. So change your defaultcontroller renderPageLinks() function to static:
public static function renderPageLinks(){
// do whatever you were doing
}
Autoload the controller, by modifying main configuration main.php inside protected/config/ folder:
// autoloading model and component classes
'import'=>array(
'application.models.*',
'application.components.*',
'application.modules.quickdial.controllers.*' // this line is added
),
Then call your static function directly:
$this->widget('pageLinkGen', array('pages' => DefaultController::renderPageLinks()));
Of course for this static method to work, you must have only one module with controller DefaultController, or you must not import other modules' controllers, in any case name conflicts could arise.
Three
If you move the function into a controller in the main module(i.e pageLinkGen controller that you have mentioned), then you'll have to import the model that you need into the main module's config main.php(so that yii can find it), to autoloading import array add :
// autoloading model and component classes
'import'=>array(
'application.models.*',
'application.components.*',
'application.modules.quickdial.models.*' // this line is added
),
so that your controller can find the model.