How to define a theme for a module?
#1
Posted 11 July 2012 - 08:12 AM
The theme folder should be inside the module and should have layout files and view files of that module
#2
Posted 11 July 2012 - 07:48 PM
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';
#3
Posted 12 July 2012 - 04:16 AM
Aruna Attanayake, on 11 July 2012 - 07:48 PM, said:
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
#4
Posted 12 July 2012 - 05:39 AM
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?
#5
Posted 12 July 2012 - 09:40 AM
<?php echo Yii::app()->getModule('admin')->getBaseUrl(); ?>\themes\admin\css\main.css"
should work.
#6
Posted 12 July 2012 - 09:46 AM
razorfish, on 12 July 2012 - 05:39 AM, said:
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?
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;
}
}
#7
Posted 13 July 2012 - 03:35 AM
there is no function getBaseUrl() , it's getBasePath which not works for me
@Aruna
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
#8
Posted 13 July 2012 - 04:20 AM
razorfish, on 13 July 2012 - 03:35 AM, said:
there is no function getBaseUrl() , it's getBasePath which not works for me
@Aruna
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
Attached File(s)
-
folder_structure.jpg (30.53K)
Number of downloads: 38
#9
Posted 13 July 2012 - 04:37 AM
Aruna Attanayake, on 13 July 2012 - 04:20 AM, said:
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?
#10
Posted 13 July 2012 - 04:56 AM
razorfish, on 13 July 2012 - 04:37 AM, said:
Inside modules/admin
Attached File(s)
-
folder_structure_1.jpg (14.34K)
Number of downloads: 27
#11
Posted 13 July 2012 - 09:56 AM
1) wich url do you put on webbrowser to access admin area?
2) 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
#12
Posted 15 July 2012 - 05:27 AM
razorfish, on 13 July 2012 - 09:56 AM, said:
1) wich url do you put on webbrowser to access admin area?
2) 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
1) http://localhost/tik...n/default/login
2)
<link rel="stylesheet" type="text/css" href="/tiki-ums/protected/modules/admin/themes/admin/css/screen.css" media="screen, projection" />
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';
#13
Posted 16 July 2012 - 08:21 AM
Aruna Attanayake, on 15 July 2012 - 05:27 AM, said:
Yii::app()->themeManager->baseUrl = Yii::app()->baseUrl . '/protected/modules/admin/themes';
Yes!!! That was the problem
Thank you very much 4 your help Aruna!

Help













