Written  and Posted by ePatronus Enterprise IT Solutions Islamabad, Pakistan.


we know Yii framework is the MVC (Model, View and Controller) based framework and is open source web application development framework written in PHP5 that provides the powerful, secured and fast development.

As far as its performance is concerned, Yii framework in the best choice for any type of project (in the sense of its size and performance).


STEP ONE: First of all I assume that you have a website which is working fully without any bugs or errors, before making any changes we first create a theme of our existing PHP/HTML website.

download the yii framework http://www.yiiframework.com/ and extract the folder in C:\wamp\www,  give it a proper short name i.e. yiiroot or whatever you want to give.

<click on the image to zoom>


install the CodeLobster , which simplifies php development process. You don’t need to keep in mind names of functions, arguments, tags and their attributes; methods etc – we’ve implemented all these for you in the autocomplete feature for PHP, HTML, JavaScript and even CSS.http://search.4shared.com/q/1/codelobsterphpeditionsetup?view=ls&suggested


After installation go to Tools / Preferences/ +yii / settings and set the paths to php.exe and yii framework, you can see in the image that how the paths are set, after setting the path click apply and ok. Now your CodeLobster path is set to the PHP and Yii Frame work and you can create a project in yii.


>>now click on plugins/ yii/ create project. this will open a new window


give a name to your project, i.e. I have given mywebsite name to my project.

simply click on ok.


 >> here it gives the option to download yii, if you have not downloaded the yii from http://www.yiiframework.com website, you can download it from here as given in the picture, but now it is not necessary because we have already downloaded and copied into [wamp/ www] directory.

simply click the next button.


>> if you want to create a database for your website you can check the checkbox otherwise don’t select it. Give the user name of your PhPmyadmin , by default its name is root and have no password.

>>click on the next


>> here you can specify the database host name, by default it is localhost.

>>click on finish


now another window will be open, which will ask to create an application under the defined directory.

type  y  and press enter.


Now your new yii project is created and you can edit and develop it in CodeLobster.

STEP TWO: We should follow the rule of easy to difficult, so first we make our website theme.

for this purpose create a folder under themes, give it a name i.e mytheme and copy all the images, java-script and css folders in it, and also copy the view folder from classic theme and paste it in mytheme, (classic theme is by default theme of yii project). Here we customizing our website theme (which will be the design of your PHP website).


>>open the main.php file in layouts folder of the theme.


copy the code of header and footer from your PHP/HTML website and paste in main.php file. Here I am using my own design of my website, you should use your own website code.

Converting Some Coding Syntax.

include the <?php echo Yii::app()->theme->baseUrl; ?>in all images and javascript links. Your theme will automatically get the path of every file. In all pages which you are including , make sure that every path is in yii format, otherwise the images and javascript will not be showing.

1): in normal PHP we write <img src=”media/xyzimage.png”  /> for the image link  but in Yii we will write <img src=”<?php echo Yii::app()->theme->baseUrl; ?>/media/xyzimage.png”  />

2) in normal PHP we write <script src=”js/jquery1.js” type=”text/javascript”></script> for the link of javascript file but in Yii we do as <script src=”<?php echo Yii::app()->theme->baseUrl; ?>/js/jquery1.js” type=”text/javascript”></script>



……//dots means there is another code also, i have provided only chunks of data.

<link rel=”icon” href=”<?php echo Yii::app()->theme->baseUrl; ?>/images/image1.png” />
<link rel=”shortcut icon” href=”<?php echo Yii::app()->theme->baseUrl; ?>/images/image2.ico” />

//after every image src we will include <?php echo Yii::app()->theme->baseUrl; ?>

<script src=”<?php echo Yii::app()->theme->baseUrl; ?>/js/jquery1.js” type=”text/javascript”></script>
<script src=”<?php echo Yii::app()->theme->baseUrl; ?>/js/jquery2.js” type=”text/javascript”></script>
<script src=”<?php echo Yii::app()->theme->baseUrl; ?>/js/jquery3.js” type=”text/javascript”></script>

 <img src=”<?php echo Yii::app()->theme->baseUrl; ?>/media/xyzimage.png”  />



 <?PHP echo $content; ?>



<?php echo CHtml::link(‘About Us’,array(‘site/AboutUs’)); ?>
<?php echo CHtml::link(‘Services’,array(‘site/services’)); ?>
<?php echo CHtml::link(‘Clients’,array(‘site/clients’)); ?>
<?php echo CHtml::link(‘Site map’,array(‘site/sitemap’)); ?>



now I assume that you have put the code of header and footer from your PHP website (which you want to convert) and mentioned a line of   <?PHP echo $content; ?> in the middle of header and footer.

go to protected/config and open the main.php file, and add the name of your theme folder which is mytheme, i.e.


return array(
    ‘name’=>’your website name/ heading’,


you have made your website theme in yii, it means that your design is converted from PHP/HTML to yii framework MVC.

to get an idea you should first study that how yii framework works and what are Model, View and Controller  http://www.yiiframework.com/doc/guide/1.1/en/basics.mvc, you can see your yii website controllers in protected/ controllers. we have a default SiteController.php in controllers folder, and many by default views in protected/views. In SiteController.php we represent the action functions that render the view files.


i.e. when we open the SiteController.php file we see the following piece of code.


public function actionIndex()
        // renders the view file ‘protected/views/site/index.php’
        // using the default layout ‘protected/views/layouts/main.php’


It means that actionIndex function render the index view. if we open the view folder we can see the index.php file. In index.php file you should enter the data of your home / index page from PHP/HTML or non-yii website. The Theme it is made once and using by all views and we will not include it again and again in our views pages like we do in normal PHP website when we include the header and footers in all the images. You should create the views in yii for all the pages which are in normal PHP. for example you have 5 pages of Home, About Us, Projects, Services and Contact Us, you should create the Five views manually in your protected/views/site , folder.


now you have created the views now in controller SiteController.php, you should create an action for every view to render them.

for example you can do this


public function actionIndex()
        //actionIndex will render the index view (index is the name of view file.)

    public function actionAboutUs()
        //actionAboutUs will render the aboutus view (aboutus is the name of view file.)


STEP THREE: Now you can browse your website from browser  as http://localhost/mywebsite

>>and here is our website.





  1. Thanks for your marvelous posting! I quite enjoyed reading it, you’re a great author.I will make certain to bookmark your blog and will often come back down the road. I want to encourage you continue your great posts, have a nice afternoon!|

Leave a Reply to ether money Cancel reply

Your email address will not be published. Required fields are marked *