Tuesday, November 12, 2013

Yii-GETTING STARTED WITH Yii BLOG DEMO 1 (Zend Studio)


-
1) PREPARATION
2) SETUP
3) USING ZEND STUDIO TO BROWSE THE PROJECT FOLDER AND FILES
4) VIEWING STARTUP FILES
-

1) PREPARATION

1.1) Download Yii package, e.g yii-1.1.14.f0fee9.tar.gz from http://www.yiiframework.com/download/ or directly from https://github.com/yiisoft/yii/releases/download/1.1.14/yii-1.1.14.f0fee9.tar.gz 
1.2) 7-zip portable to perform zip/unzip
1.3) XAMPP xampp-win32-1.8.1-VC9
1.4) Eclipse-style IDE. (In this tutorial, we will use Zend Studio V.10). Our aim is to use this IDE to easily find files and folders and view their code outlines. We are not going to create PHP applications using this IDE.

2) SETUP

2.1) Setup Virtual Host.
2.1.1) Edit the host file, i.e c:\windows\system32\drivers\etc\hosts by adding the following entries (refer line no. 20 and 21):
127.0.0.1 site1.local
127.0.0.1 site2.local
2.1.2) Edit the the httpd-vhosts file, i.e C:\xampp\apache\conf\extra\httpd-vhosts.conf by:
a) Uncommenting line no. 19
b) Adding new entries as follows (refer the line no.):
<VirtualHost *>
    ServerAdmin admin@localhost.com
    DocumentRoot "C:/xampp/htdocs"
    ServerName localhost
</VirtualHost>
<VirtualHost *>
    ServerAdmin admin@localhost.com
    DocumentRoot "C:/projects/site1"
    ServerName site1.local
         <Directory "C:/projects/site1">
                        AllowOverride all
                        Order allow,deny
                        Allow from all
                        Require all granted
         </Directory>        
</VirtualHost>
<VirtualHost *>
    ServerAdmin admin@localhost.com
    DocumentRoot "C:/projects/site2"
    ServerName site2.local
         <Directory "C:/projects/site2">
                        AllowOverride all
                        Order allow,deny
                        Allow from all
                        Require all granted
         </Directory>        
</VirtualHost>
2.1.3) Create directory structure as follows:
2.2) Extract yii package.
2.2.1) Run 7-zip.
Browse yii file and select the items as follows:
2.2.2) Click Extract button and type into Copy to box “C:\projects\site1\”
2.2.3) Outcome:
2.3) Test the Setup.
2.3.1) Restart Windows.
2.3.2) Run XAMPP and Start Apache and MySQL.
2.3.3) Browse URL http://site1.local/demos/blog 

3) USING ZEND STUDIO TO BROWSE THE PROJECT FOLDER AND FILES

The idea of using Zend Studio is to take the advantage of its View Perspective. Alternatively, an ordinary Eclipse EDI or other equivalent software can be used as well.
3.1 Run Zend Studio (The icon normally will be placed on Windows desktop screen, unless you skip it during installation).
3.2) Notice the following panel:
a) File Explorer.
b) Source View/Editor.
c) Outline Viewer
3.3) Go to menu file/new/project...
3.4) Select General Project.
3.5) Set Project Name and Location.
Click Finish.
3.6) Outcome:

4) VIEWING STARTUP FILES

4.1) From Step 3.6, double-click index.php
4.2) Notice the Outline Panel showing the corresponding outlines.
4.3) Refer Step 4.1.
Line 4 tells the location of Yii Framework
Line 5 tells the location of Application Main Configuration.
Line 11 runs the WebApplication Object.
4.4) In the File Explorer panel, double-click yii.php and YiiBase.pphp respectively.
4.5) Line no. 5 of yii.php tells us that Yii class is derived (extends from) YiiBase
4.6) Line no. 98 of YiiBase.php tells us that the method createWebApplication returns an object of type CWebApplication based on the value given by $config.
4.7) Open file Framework/Web/CWebApplication.php. Notice that:
CWebApplication is derived (extends) from CApplication.
Default Application Controller is site (SiteController.php)
Default Application Layout is main (main.php)
4.8) Open file Framework/base/CApplication.php. Notice that:
There is a public method run()
4.9) The steps above help to show the logics of line no.11 of the index.php
Literally, we can say…
… Call the static Method createWebApplication of the Class Yii…
...  to return an Object based on the class CWebApplication …
… and call the run method which is inherited from the class CApplication …
… to start the web application.
4.10) For a beginner, the logics in step 4.9 looks rather complicated. This is the real life example of the application of Object Oriented Programming. Nevertheless, as we proceed to build and run web application based on Yii, we will see more and more examples of this kind and get used to it.

2 comments:

Labels