Step Two:Hello World - "My first application on Yii"

Installing Yii

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:
  1. Download the Yii Framework from http://www.yiiframework.com/download/.
  2. Unpack the downloaded file to a web-accessible folder.
After installation, it is advised that you verify that your server satisfies all of the requirements for using Yii and to ensure the installation was a success. Luckily, doing so is easy. Yii comes with a simple requirement checking tool. To invoke the tool and have it verify the requirements for your installation, simply point your browser to:

http://yourhostname/path/to/yii/requirements/index.php 

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-
  1.  To enable the 'Gii' ; go to protected/config/main.php
  2. Find out the lines below and uncomment it. Don't forget to specify your password:
  3.  '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'),
            ),
  4. Just go to the browser and paste the address on the address bar 
  5. http://localhost/resume/index.php?r=gii;
  6. Don't panic; 'resume' is the root folder in my case. 
  7. Enter the password you just mentioned in  main.php and hit the enter.
  8. You will see some links: click on 'Controller Generator' link.
  9. 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'. 
  10. 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. 
  11. Then click on preview and then generate buttons one after one. 
  12. 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. 
  13. navigate throught http://localhost/resume/index.php?r=post
  14. you will see the index action page is being rendered because no action is specified.
  15. http://localhost/resume/index.php?r=post/helloworld
  16. In this case action actionHelloworld() will be called. 
  17. $this->render('helloworld'); renders this action as a view. 
  18. Suppose , you have to render some text like 'hello world !!' in the view; 
  19. $this->render('helloworld',array('msg'=>'hello world'));
  20. In /views/helloworld.php ; if we echo $msg; message 'hello world' will be displayed.
 

2 comments:

  1. i was always looking for this kind of post. It will be a great support for me.

    ReplyDelete
  2. Very useful post thnkyou

    ReplyDelete