Starting Out with the Yii PHP FrameworkSeptember 3, 2012
Developers are quickly switching from older frameworks like CodeIgniter to Yii, which allows for quicker deployment of PHP web applications. Here are some steps to get started with Yii on Mac:
- Download the Yii framework.
- Unarchive the download, enter your command line of choice, and run chmod -R 755 on the directory to make the necessary files accessible and executable.
cdinto the framework folder and run this command:
$ yiic webapp your/htdocs/location
Now you’ve created a “skeleton” for your web application. Start up your Apache server, if you haven’t already, and open the webpage that you chose before. Ex:
You should see the Yii welcome page. Now open
your/location/protected/config/main.phpin your text editor and add this to the configuration:
return array( ...... 'import'=>array( 'application.models.<em>', 'application.components.</em>', ), 'modules'=>array( 'gii'=>array( 'class'=>'system.gii.GiiModule', 'password'=>'enter-a-password-here', ), ), );
Point your web browser to
http://localhost/your/location/index.php?r=giiand open the Model Generator.
- Use Yii to generate code for a model with the Table Name
tbl_userand the Model Class
- In the sidebar, select the CRUD Generator to generate code to implement CRUD operations. Create code for the Model Class
Userand the Controller ID
user. Once again preview and generate the code.
- Now, if you open
http://localhost/your/location/index.php?r=userin your web browser, you should see a list of all the entries in the default
- Go to
http://localhost/your/location/index.php?r=user/admin(the admin function of the user class) and log in using the gii password you choose earlier (in the main configuration file). From here, you can perform the various CRUD operations such as listing, editing, and creating entries in the database.
Yii allows for the quick development of PHP applications by simplifying processes such as writing code to perform CRUD operations by generating the code for you.