Prior to installing Yii, you must configure your application development environment as a web server capable of supporting PHP 5.1.0 or higher. Yii has been thoroughly tested with Apache HTTP server on Windows and Linux operating systems. It may also run on other web servers and platforms, provided PHP 5 is supported. There are myriad free resources available on the Internet to assist you in getting your environment configured with a PHP 5 compatible web server. We assume the reader has previously engaged in PHP development and has access to such an environment. We will leave the installation of a web server and PHP itself as an exercise to the reader.
The basic Yii installation is almost trivial. There are really only two necessary steps:
- Download the Yii Framework from http://www.yiiframework.com/download/.
- Unpack the downloaded file to a web-accessible folder.
Using the Requirement Checker is not itself a requirement for installation, but it is certainly recommended to ensure proper installation. As you can see, not all of our results under the Details section received a Passed status, as some display a Warning. Of course, your configuration will most likely be slightly different from ours and consequently, your results may slightly differ as well. That is okay. It is not necessary that all of the checks under the Details section pass, but it is necessary to receive the following message under the Conclusion section:
Your server configuration satisfies the minimum requirements by Yii.
Hello World !!!Yii, has provided us many facilities, including one of the 'gii'. With the advent of 'Yii', we can save our precious time to think more over on logics . 'Gii' provides us the facility through which we can save our time in a great extent. You will see that not even a single line of code we write but 'Gii' will write a streamlined code for us by its own. Just follow the steps below ; as it is-
- To enable the 'Gii' ; go to protected/config/main.php
- Find out the lines below and uncomment it. Don't forget to specify your password:
- 'modules' => array(
// uncomment the following to enable the Gii tool
'gii' => array(
'class' => 'system.gii.GiiModule',
'password' => '112233',
// If removed, Gii defaults to localhost only. Edit carefully to taste.
'ipFilters' => array('127.0.0.1', '::1'),
- Just go to the browser and paste the address on the address bar
- Don't panic; 'resume' is the root folder in my case.
- Enter the password you just mentioned in main.php and hit the enter.
- You will see some links: click on 'Controller Generator' link.
- In Controller ID text box , just mention the name of the controller; if you write 'post' , then postController.php file will be generated in which there would be a class 'PostController'.
- In Action ID text box, name of the actions should be mentioned; if you want to enter multiple action at one go; just write actions name seperated with commas or space.
- Then click on preview and then generate buttons one after one.
- That's it; if you see in /protected/controllers/ folder; you can see the postController.php file has been created automatically. Apart from this file; go to /protected/views/post/ you can see some other files have been created.
- navigate throught http://localhost/resume/index.php?r=post
- you will see the index action page is being rendered because no action is specified.
- In this case action actionHelloworld() will be called.
- $this->render('helloworld'); renders this action as a view.
- Suppose , you have to render some text like 'hello world !!' in the view;
- $this->render('helloworld',array('msg'=>'hello world'));
- In /views/helloworld.php ; if we echo $msg; message 'hello world' will be displayed.