rafayZia
(Rafay 07)
December 3, 2013, 11:00am
1
Hi there, i am working on a project. It was fine until i installed new windows on my PC. But now project is same and when i access
Yii::app()->controller->module
it returns null. When i viewed config file it had admin module in it. I dont know why is it returning null. Cant find a way out.
Thanks for your help.
This might be you are expecting…
Yii::app()->controller->module->id;
rafayZia:
Hi there, i am working on a project. It was fine until i installed new windows on my PC. But now project is same and when i access
Yii::app()->controller->module
it returns null. When i viewed config file it had admin module in it. I dont know why is it returning null. Cant find a way out.
Thanks for your help.
rafayZia
(Rafay 07)
December 4, 2013, 5:48am
3
i was also expecting but this is also returning null.
Hi,
You try request from your browser like yourapp.com/yourmodule Then only the following code works!
if (Yii::app()->controller->module != "") {
Yii::app()->controller->module->getName() ;
}
Cheers!
rafayZia
(Rafay 07)
December 4, 2013, 7:02am
5
thanks for reply, when i access my module through url, it works but i dont know why controller->moduleis returning null because on the base of this value i have to select the view to render to user.
when i try getName() as you suggested, it gives error
Call to a member function getName() on a non-object on some line
As you stated if you access the module through url only it works! otherwiese the object will not be having the module properties
so you can’t get the module’s name through controller->modules.
If you want to get all the available modules and do the if condition go here
Or
If you wish to decide the view file when the user request for specific module the above code I suggested in this thread will be help full for you!.
let me know if i misunderstood anything!!
Cheers!
rafayZia:
thanks for reply, when i access my module through url, it works but i dont know why controller->moduleis returning null because on the base of this value i have to select the view to render to user.
when i try getName() as you suggested, it gives error
Call to a member function getName() on a non-object on some line
rafayZia
(Rafay 07)
December 4, 2013, 7:36am
7
As you stated if you access the module through url only it works! otherwiese the object will not be having the module properties
so you can’t get the module’s name through controller->modules.
If you want to get all the available modules and do the if condition go here
Or
If you wish to decide the view file when the user request for specific module the above code I suggested in this thread will be help full for you!.
let me know if i misunderstood anything!!
Cheers!
thanks. Actually i dont want to get all modules, i just want to check which module is it. here is my code may be it could give a clear picture about what i want to implement.
if (Yii::app()->controller->module->id === 'admin') {
$this->widget('bootstrap.widgets.TbNavbar', array(
'brand' => 'Admin Area',
'htmlOptions'=>array('role'=>'navigation','aria-label'=>"Site Navigation"),
'items' => array(
array(
'class' => 'bootstrap.widgets.TbMenu',
'items' => array(
array('label' => 'Home', 'url' => 'admin/index'),
array('label' => 'Our Clients', 'url' => yii::app()->CreateUrl('/admin/ourClients')),
array('label' => 'Portfolio', 'url' => yii::app()->CreateUrl('/admin/portfolio')),
)
)
)
));
}
elseif (Yii::app()->controller->module->id === 'spicelab'&& !yii::app()->user->isGuest)
echo $this->renderPartial('indexComponents/labView');
This may be the right code…
if (Yii::app()->controller->module != "") { //If the user access the module i.e site.com/module_name/controller/action and more with only modules
if (Yii::app()->controller->module->id === 'admin') {
$this->widget('bootstrap.widgets.TbNavbar', array(
'brand' => 'Admin Area',
'htmlOptions' => array('role' => 'navigation', 'aria-label' => "Site Navigation"),
'items' => array(
array(
'class' => 'bootstrap.widgets.TbMenu',
'items' => array(
array('label' => 'Home', 'url' => 'admin/index'),
array('label' => 'Our Clients', 'url' => yii::app()->CreateUrl('/admin/ourClients')),
array('label' => 'Portfolio', 'url' => yii::app()->CreateUrl('/admin/portfolio')),
)
)
)
));
} elseif (Yii::app()->controller->module->id === 'spicelab' && !yii::app()->user->isGuest)
echo $this->renderPartial('indexComponents/labView');
}else{
//Code for site.com/controller/action goes on
}
rafayZia:
thanks. Actually i dont want to get all modules, i just want to check which module is it. here is my code may be it could give a clear picture about what i want to implement.
if (Yii::app()->controller->module->id === 'admin') {
$this->widget('bootstrap.widgets.TbNavbar', array(
'brand' => 'Admin Area',
'htmlOptions'=>array('role'=>'navigation','aria-label'=>"Site Navigation"),
'items' => array(
array(
'class' => 'bootstrap.widgets.TbMenu',
'items' => array(
array('label' => 'Home', 'url' => 'admin/index'),
array('label' => 'Our Clients', 'url' => yii::app()->CreateUrl('/admin/ourClients')),
array('label' => 'Portfolio', 'url' => yii::app()->CreateUrl('/admin/portfolio')),
)
)
)
));
}
elseif (Yii::app()->controller->module->id === 'spicelab'&& !yii::app()->user->isGuest)
echo $this->renderPartial('indexComponents/labView');