Yii Framework Forum: How to define a theme for a module? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How to define a theme for a module? Rate Topic: -----

#1 User is offline   razorfish 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 04-July 12

Posted 11 July 2012 - 08:12 AM

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
0

#2 User is offline   Aruna Attanayake 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 107
  • Joined: 08-September 11
  • Location:Colombo - Sri Lanka

Posted 11 July 2012 - 07:48 PM

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';

Extensions:
SFTP

PageSize

Dashboard
0

#3 User is offline   razorfish 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 04-July 12

Posted 12 July 2012 - 04:16 AM

View PostAruna Attanayake, on 11 July 2012 - 07:48 PM, said:

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 :)
0

#4 User is offline   razorfish 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 04-July 12

Posted 12 July 2012 - 05:39 AM

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?
0

#5 User is offline   bglee 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 152
  • Joined: 21-November 10
  • Location:Oak Park, IL

Posted 12 July 2012 - 09:40 AM

@razorfish, something like:
<?php echo Yii::app()->getModule('admin')->getBaseUrl(); ?>\themes\admin\css\main.css"

should work.
It takes 2 points to draw a straight line, but at least 3 to draw a conclusion.
0

#6 User is offline   Aruna Attanayake 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 107
  • Joined: 08-September 11
  • Location:Colombo - Sri Lanka

Posted 12 July 2012 - 09:46 AM

View Postrazorfish, on 12 July 2012 - 05:39 AM, said:

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?


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;
	}
}

Extensions:
SFTP

PageSize

Dashboard
0

#7 User is offline   razorfish 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 04-July 12

Posted 13 July 2012 - 03:35 AM

@bglee
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
0

#8 User is offline   Aruna Attanayake 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 107
  • Joined: 08-September 11
  • Location:Colombo - Sri Lanka

Posted 13 July 2012 - 04:20 AM

View Postrazorfish, on 13 July 2012 - 03:35 AM, said:

@bglee
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)


Extensions:
SFTP

PageSize

Dashboard
0

#9 User is offline   razorfish 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 04-July 12

Posted 13 July 2012 - 04:37 AM

View PostAruna Attanayake, on 13 July 2012 - 04:20 AM, said:

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?
0

#10 User is offline   Aruna Attanayake 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 107
  • Joined: 08-September 11
  • Location:Colombo - Sri Lanka

Posted 13 July 2012 - 04:56 AM

View Postrazorfish, on 13 July 2012 - 04:37 AM, said:

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

Attached File(s)


Extensions:
SFTP

PageSize

Dashboard
0

#11 User is offline   razorfish 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 04-July 12

Posted 13 July 2012 - 09:56 AM

Aruna 2 final question and I wont disturb you anymore


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
0

#12 User is offline   Aruna Attanayake 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 107
  • Joined: 08-September 11
  • Location:Colombo - Sri Lanka

Posted 15 July 2012 - 05:27 AM

View Postrazorfish, on 13 July 2012 - 09:56 AM, said:

Aruna 2 final question and I wont disturb you anymore


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';

Extensions:
SFTP

PageSize

Dashboard
0

#13 User is offline   razorfish 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 04-July 12

Posted 16 July 2012 - 08:21 AM

View PostAruna Attanayake, on 15 July 2012 - 05:27 AM, said:

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!
0

#14 User is offline   widyana 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 08-August 12

Posted 08 August 2012 - 12:59 PM

Great thread, solve my problems quickly.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users