What is $_GET['tag'] in Blog Demo

This is the code of the index action in the Blog demo:

public function actionIndex()


    $criteria=new CDbCriteria(array(


        'order'=>'update_time DESC',






    $dataProvider=new CActiveDataProvider('Post', array(











One thing troubles a lot is the


. It’s not how it works in the PHP manual.

According to PHP manual, tag should be be in the

<input name = "tag"...> </input>,

but I couldn’t find any ‘tag’ in the view file of index action of the PostController.

Can you tell me what’s wrong?

Thank you!

I don’t think so…

$_GET[‘tag’] is not supposed inside the <input name=“tag” />, because if so, it should be $_POST[‘tag’].

This $_GET[‘tag’] is supposed you are clicking one of the tag, and it will list down all the blog post with corresponding tag.

For example you are clicking "sport" tag…

then the URL will look like this


In the controller to retrieve the tag value (which is “sport”), we need to write $_GET[‘tag’]. Use that value and do query then display the result.

NB: If you try blog demo on your localhost, you might want to disable the URL Manager first, to see the url that I just wrote. Because by default the example enables the url manager. Go to /protected/config/main.php

and comment this line










Isn’t the following URL is the result of form with action method = GET?


My confusion is that I couldn’t find any form in the final HTML code.

This is the actual HTML code about tag:

<div class="portlet-content">

<span class="tag" style="font-size:9pt"><a href="/yii/demos/blog/index.php/posts/blog">blog</a></span>

<span class="tag" style="font-size:9pt"><a href="/yii/demos/blog/index.php/posts/test">test</a></span>

<span class="tag" style="font-size:9pt"><a href="/yii/demos/blog/index.php/posts/yii">yii</a></span>


It’s just a link, no form. How could this <a> tag generate a $_GET array? Only <form> with method = GET can generate a $_GET array. Is it right?

Please let me know your thinking. Thank you!

If you take a look at the code of CUrlRule you can find this:

public function parseUrl($manager,$request,$pathInfo,$rawPathInfo)





			foreach($this->defaultParams as $name=>$value)






			foreach($matches as $key=>$value)




				else if(isset($this->params[$key]))



			if($pathInfo!==$matches[0]) // there're additional GET params



				return strtr($this->route,$tr);


				return $this->route;




There’s no difference between a form with method=“get” and a link with a query string. Both can generate the same $_GET data.

Thanks a lot! This is new to me. Is this knowledge well known to other people?