Yii Application Structure

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>



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

		<title>My awesome app</title>



		<div id="wrapper">

			// partial header

			// partial home

			// partial some section 1

			// partial some section 2

			// partial footer




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

Thank you :)

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

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:




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:




Recommended you read http://www.yiiframework.com/doc/guide/1.1/en/quickstart.first-app

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.

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

Look this can help.

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.yiiframework.com/doc/api/1.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)


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)



		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?