Is it possible to define a theme for a module (admin)? How can i do this?
The theme folder should be inside the module and should have layout files and view files of that module
Is it possible to define a theme for a module (admin)? How can i do this?
The theme folder should be inside the module and should have layout files and view files of that module
Try out this
in your module class inside init() method define like below.There should be a themes folder inside your module folder. I checked with my admin module and worked fine.
Yii::app()->themeManager->basePath = Yii::app()->basePath . '\modules\admin\themes';
Yii::app()->theme = 'admin';
It works!!!
And since view folder should be inside \themes\admin i aded this
$vPath = Yii::app()->themeManager->basePath."\\".Yii::app()->theme->name.'\views';
$this->setViewPath($vPath);
Thank you very much for your help Aruna
Well there is another problem here though
In modules\admin\themes\admin\views\layouts\main.php there is
<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->theme->baseUrl; ?>/css/main.css" />
What is doing here is trying to get the main.css file wich is located on the frontend theme folder and not the one that is inside the admin module theme folder…
Any solution here?
@razorfish, something like:
<?php echo Yii::app()->getModule('admin')->getBaseUrl(); ?>\themes\admin\css\main.css"
should work.
Hi,
This may occur that you are not set the theme base path as previous post. I don`t think you need to set view paths. This is how my module class look like
class AdminModule extends CWebModule
{
public function init()
{
// this method is called when the module is being created
// you may place code here to customize the module or the application
// import the module-level models and components
$this->setImport(array(
'admin.models.*',
'admin.components.*',
));
$this->setComponents(array(
'errorHandler' => array(
'errorAction' => '/admin/default/error'),
));
Yii::app()->themeManager->basePath = Yii::app()->basePath . '\modules\admin\themes';
Yii::app()->theme = 'admin';
Yii::app()->user->setStateKeyPrefix('_admin');
Yii::app()->user->setReturnUrl('/admin');
Yii::app()->user->loginUrl = Yii::app()->createUrl('admin/default/login');
Yii::app()->homeUrl = array('default/home');
Yii::app()->language = 'en';
}
public function beforeControllerAction($controller, $action)
{
if(parent::beforeControllerAction($controller, $action))
{
// this method is called before any module controller action is performed
// you may place customized code here
return true;
}
else
return false;
}
}
there is no function getBaseUrl() , it’s getBasePath which not works for me
The viewpath is needed becouse if I remove it, its says me that it cannot find the view. And I’ve already set the theme base path as you mention above.
I see your AdminModule file. It seems that your css files and maybe the view files are not inside the theme folder. If this is true well this is not my case and this is why the above code you mention does not work for me
Hi razorfish,
I attached the theme folder structure. This may clear out conflicts. All css and view files are reside on it, but view files relevant to models are under module/views folder.
Thanks
Aruna
Aruna, where is located the theme folder in the picture above? On the root folder of your app OR inside the admin module folder?
Inside modules/admin
Aruna 2 final question and I wont disturb you anymore
wich url do you put on webbrowser to access admin area?
if you dou right click -> view source in the index page of admin area plese copy and paste one
line that css is embended in the header section
mine is
<link rel="stylesheet" type="text/css" href="/mysite.com/themes/admin/css/screen.css" media="screen, projection" />
which should not be that way i think
[html]<link rel="stylesheet" type="text/css" href="/tiki-ums/protected/modules/admin/themes/admin/css/screen.css" media="screen, projection" />[/html]
Sorry bro, I missed to include one line in my module init() method in previous post. Add below line also before setting the theme name.
Yii::app()->themeManager->baseUrl = Yii::app()->baseUrl . '/protected/modules/admin/themes';
Yes!!! That was the problem I should have figoured it out myself though. It was not difficult.
Thank you very much 4 your help Aruna!
Great thread, solve my problems quickly.