Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Understanding how Yii PHP Framework works Am I right?

Posted on 2011-09-06
Medium Priority
Last Modified: 2013-11-10
I recently have been trying to learn Yii and PHP together.
I have hit a road block in my understanding. I see it works on the Trackstar example code from
"Agile Web Application Development with Yii 1.1 and PHP5"

I can not understand how an action like
<form id="project-form" action="/trackstar/index.php?r=project/create" method="post">
      <p class="note">Fields with <span class="required">*</span> are required.</p>
 as the HTML rendered looks like the above

triggers a record creation. Could someone explain the program flow?
project is the projectController.php  and create is the view involved but how does the actual
SQL command  Insert   .. $model data ... get executed?
Is the create view essential for the name? Do I have to override whatever other view name I use? Someone help  me out here????
Does this happen via get and Post?? e.g after post then the data is saved
via the if(isset($_POST['Project']))
May be I am right here has it been there the whole time.
1. call up url from menu or type into browser:  to render the form as a get
e.g http://localhost/trackstar/index.php?r=project/create 
press the submit button and go to the same URL but as a  post -
call save funcion code within the parent of the model, CActivateRecord

Here is the actionCreate function:
      public function actionCreate()
            $model=new Project;

            // Uncomment the following line if AJAX validation is needed
            // $this->performAjaxValidation($model);

            fwrite($fp0," Got 2 start of actionCreate");

            fwrite($fp1," We Got POST SO WE ARE INSERTING DATA");

            $this->render('create',array( 'model'=>$model,));
            fwrite($fp," Got here to end");

In fact it makes sense that the parent class CActiveRecord of the model here contains the
save function which actually saves the data base record.
Can anyone comment on this finding? Maybe this will help others like myself
Question by:Robert Silver
  • 3
  • 2
LVL 111

Expert Comment

by:Ray Paseur
ID: 36495516
Not sure exactly where to start, and you might want to break this line of inquiry down into several questions, since it seems to be all over the Yii and PHP map.  Perhaps the best response is to provide you some learning resources.

You can make a Google search for "learn Yii Framework" -- I did and found many apparently good learning resources.

If you're not rock-solid in your PHP skills, you might want to learn the basics of PHP through the well-explained examples in these two books.

Frameworks are typically object-oriented, and Yii is no different, so you will need to understand object-oriented PHP programming.  This page and all the linked pages will give you something of a flavor for that.

And this book will help add some foundation to your understanding of OOP.

Some additional interesting information is available here:


Author Comment

by:Robert Silver
ID: 36501981
While your reply is somewhat helpful I was looking for confirmation of my understanding whcih recent progress has vindicated.
 Today I  have more questions. Since no else has come forward and actually
validated statements I know to be true I will sum it up as this.
My understanding was dead on.  You get the  view or form and post the results typically in the yii framework standard.   You pass a model and run your view from the controller like most MVC frameworks.  The post of the form data back to the controller is handled through the action url of the form  View used to populate typically a database.

Proof of work helps! For all those other people interested.'
LVL 111

Expert Comment

by:Ray Paseur
ID: 36503276
Sorry, I did not understand that the question was about post of the form data back to the controller is handled through the action url of the form.  Please let me add this link to the collected learning resources above.

HTH, ~Ray

Author Comment

by:Robert Silver
ID: 36506919
As I said before. I assumption was in fact correct The demo TrackStar application in fact uses the
get method displaying a form or view page and  Post to process the results of said view page.
I think it will be helpful for others struggling to understand Yii Framework and how it gets implemented in a classic fashion e.g Trackstar demo.
LVL 111

Accepted Solution

Ray Paseur earned 2000 total points
ID: 36509978
get method displaying a form or view page and post to process the results of said view page

That is, indeed, "a classic fashion."  In fact it is a little bit more than classic.  If you make a Google search for "get vs post" you will find many results, and among them this very good little article.

In a nutshell, GET method requests use the URL to carry the request arguments.  You can send a link to a friend if the page can be retrieved with a GET request (very handy) like this:

GET requests must not modify the underlying data model -- they are just for displaying information.  As the article points out, GET should be used if and only if there are no side effects to the retrieval of data.

POST requests use the request body (a raw post string of arguments) to carry the content of the request.  You can use POST requests when you want to add, update or remove information from the underlying data model.

It's all part of the HTTP specs.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question