Yii Framework Forum: Yii Application Structure - Yii Framework Forum

Jump to content

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

Yii Application Structure How to configure my app structure? Rate Topic: -----

#1 User is offline   thcoelho 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 05-November 12

Posted 06 November 2012 - 08:49 AM

Hi guys :)

I'm new Yii user, i work with frontend and i get stucked with Yii structure.

I'm not understanding how Yii works, i've see that Yii doesn't have a public/www folder to store all my public files like images, js and css.

I want to use this structure:

|-- myapp
| |-- public
| | |-- images
| | |-- css
| | |-- js
| | |-- assets
| |-- protected
| |-- themes

Acctually i'm working in a project that use a unique view it's a single page like this: www.taylornopmc.com.br

I'd like to work with partials, each partial will be an independent section of this page.

Then i imagine a layout that will render all partials. Something like this:

<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

		<title>My awesome app</title>
	</head>
	<body>
		<div id="wrapper">
			// partial header
			// partial home
			// partial some section 1
			// partial some section 2
			// partial footer
		</div>
	</body>
</html>


I need some insights of how i can configure Yii to work like this.

Thank you :)
0

#2 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,636
  • Joined: 04-March 10
  • Location:UK

Posted 06 November 2012 - 09:38 AM

Yii already does all of these things. Start from here in the guide to get an idea for how it all fits together.
0

#3 User is offline   msoa 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 260
  • Joined: 15-August 12

Posted 06 November 2012 - 09:39 AM

Do you have tried create a yii-application with yii command?
there is following steps:(Linux)
1- download yii framework.
2- extract it on the root web directroy. like /var/www in ubuntu.
3- you may rename the contained directory of yii. for example, rename yii-1.1.12 to yii
3- now in a terminal type:
cd /var/www/

4- for create a yii new application type in terminal:
yii/framework/yiic firstApp
for question type y and press enter.
now you can a structure like it:
/var/www/
---/yii/
---/firstApp

you may also create your app within yii framework. for do it, instead of yii/framework/yiic firstApp type
yii/framework/yiic yii/firstApp

The structure is:
/var/www/
---/yii/
---/yii/firstApp

Recommended you read http://www.yiiframew...start.first-app
0

#4 User is offline   redguy 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 815
  • Joined: 02-July 10
  • Location:Central Poland

Posted 06 November 2012 - 12:06 PM

View PostKeith, on 06 November 2012 - 09:38 AM, said:

Yii already does all of these things. Start from here in the guide to get an idea for how it all fits together.

The only problem is with themes as by design they can contain both public and protected files (for example web assets like images, css, js, etc and views). However if you assume that you will not put web assets there and your themes will be simply views files - it should be possible to achieve needed structure with few configuration changes.
red
0

#5 User is offline   thcoelho 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 05-November 12

Posted 06 November 2012 - 12:50 PM

Keith and msoa,

I understand how to create a new application using yiic, but i can't understand how i can change this default webapp structure like i said above.

It's a little weird work with some folders like css / js / images outside a main folder like "public" or "www".

I'm coming from rails environment, i have too many thing to learn :P

Anyway thank you very much :)
0

#6 User is offline   msoa 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 260
  • Joined: 15-August 12

Posted 06 November 2012 - 02:10 PM

Look this can help.
0

#7 User is offline   redguy 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 815
  • Joined: 02-July 10
  • Location:Central Poland

Posted 07 November 2012 - 04:11 AM

View Postthcoelho, on 06 November 2012 - 12:50 PM, said:

Keith and msoa,

I understand how to create a new application using yiic, but i can't understand how i can change this default webapp structure like i said above.

It's a little weird work with some folders like css / js / images outside a main folder like "public" or "www".

I'm coming from rails environment, i have too many thing to learn :P

Anyway thank you very much :)

Did you figure out how to do what you want? if not:
  • to move "protected" folder out of webroot you have to simply modify "index.php" and point there its new location
  • to move "themes" folder you have to configure 'themeManager' component in your config file. there are two params to set: basePath and baseUrl (http://www.yiiframew...1/CThemeManager)
  • if you want to have some common folder for components, just add some 'import' entries in your config file (and probably path alias)

red
0

#8 User is offline   ametad 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 78
  • Joined: 08-February 12
  • Location:Holland

Posted 16 January 2013 - 04:56 AM

Good day to you all,

I am also trying to set a different path for the "themes" folder. As Redguy pointed out this could be done by configuring the themeManager component in the config file. I have tried to configure it like this:

// config/main.hpp
...

'components => array(
    ...
    'themeManager' => array(
        'class' => 'CThemeManager',
        'basePath' => '/srv/http/domainname/www/themes',
        'baseUrl' => $baseUrl.'/themes',
     ),
    ....
),

...


But it just won't set the path as declared in the config! A vardump of the configfile states the right location:
...
'themeManager' => array
        (
            'class' => 'CThemeManager'
            'basePath' => '/srv/http/domainname/www/themes'
            'baseUrl' => '/themes'
        )
...


A vardump of Yii::app()->themeManager gives the wrong configuration:
CThemeManager#1 ( [themeClass] => 'CTheme' [CThemeManager:_basePath] => '/srv/http/domainname/themes' [CThemeManager:_baseUrl] => '/themes' [behaviors] => array() [CApplicationComponent:_initialized] => true [CComponent:_e] => null [CComponent:_m] => null )


It is driving me mad... But I wont give in :)
Does anyone know how to set a different basePath for the themes? Anyone has some experience with this?

After digging a little further in the Class Reference I saw here that there is indeed a basePath property. In the sourcecode of CThemeManager itself, basePath is not a public property but instead it is set with a setter:

        /**
	 * @param string $value the base path for all themes.
	 * @throws CException if the base path does not exist
	 */
	public function setBasePath($value)
	{
		$this->_basePath=realpath($value);
		if($this->_basePath===false || !is_dir($this->_basePath))
			throw new CException(Yii::t('yii','Theme directory "{directory}" does not exist.',array('{directory}'=>$value)));
	}


In comparison with e.g. the 'db' component where among other things, you can set the properties 'username' and 'password'. In the sourcecode of CDbConnection these properties are indeed public properties.
Is this maybe the reason why the basepath of the themeManager cannot be set?

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