48 posts / categories / feed

Playing with Yii Part 2

I think the Yii screencasts that they have on the Yii Framework site is pretty simplistic and easy to understand. However this is just the tip of an iceberg what this beast can do, there is more to it. Hence supposedly it will be more fun to start exploration some possibilities and functions that Yii Framework does.

The first part of it is to get your framework downloaded, and getting an instance of Yii Framework running. As these basic stuffs are locatable on the Yii Screencasts, hence I’ll assume that this part of the knowledge is taken care of. I will just do a quick summary of things that I take note off from the screencasts.

Creating a Hello World Application

A hello world applicaiton in Yii is nothing more than a page in the application displaying this simple greeting.

  1. Use Gii to create a new controller to handle our page request
  2. Alter the view file to display our friendly greeting

Understanding the Request Route

http://localhost/demo/index.php?r=greeting/index

where  r = route, greeting = controller id, index = action id
Instruct Yii to route request to Greeting Controller::actionIndex()

How to Move message data back to the controller?

  1. Create controller property to hold message data
  2. Pass the data from controller to view

How to Output the message content to the view?

  1. Set a variable $content for the view
  2. $this->message for the view output

CRUD

Configure our application to use a database. Create CRUD content management functionality.

What does CRUD stand for?

Understanding the Request Route when using CRUD

main application : http://localhost/demo/index.php

in the message controller, viewing the details of message #1, so our route is:
r=message/view&id=1

total url: http://localhost/demo/index.php?r=message/view&id=1

How to Alter the simple Hello World message to use content from the database?

Recap:

<?php echo “Hello World” ?> – data in the view

<?php echo $content ?> – data in the controller:: push approach

<?php echo $this->message ?> – data in the controller:: pull approach

Quick References:

Yii Screencasts: http://www.yiiframework.com/screencasts/
Yii Wiki: http://www.yiiframework.com/wiki/
Yii API Documentation: http://www.yiiframework.com/doc/api/1.1/Yii