User-friendly URLs

Hello al yii users!

I am new here, and I am learnig yii, so we can propose to customers of our firm.

But first we want to test it and realizing something, just to show how it works.

Firs question: "1. Creating URLs"

In "1. Creating URLs" guide is written:

To change the URL format, we should configure the urlManager

application component so that createUrl can automatically switch

to the new format and the application can properly understand the new URLs:"

In this First Step, I want only make the first simply change

from /index.php?r=post/read&id=100


In my case

from http(:2slash)vvv-mysite-com/ush/index.php?r=alf/first&prova=Athens&ok=1

to http(:2slash)vvv-mysite-com/ush/index.php/alf/first/prova/Athens/ok/1

or something similar.

It does not work.

What is wrong in my files?

Thank you in advance!

Alf_75 Milan


// uncomment the following to define a path alias


// This is the main Web application configuration. Any writable

// CWebApplication properties can be configured here.

return array(



	// preloading 'log' component


	// autoloading model and component classes






		// uncomment the following to enable the Gii tool





		 	// If removed, Gii defaults to localhost only. Edit carefully to taste.





	// application components



			// enable cookie-based authentication



		// uncomment the following to enable URLs in path-format






				'<_c:(alf)>/<id:\d+>/<_a:(first)>' => '<_c>/<_a>',










			'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',


		// uncomment the following to use a MySQL database



			'connectionString' => 'mysql:host=localhost;dbname=testdrive',

			'emulatePrepare' => true,

			'username' => 'root',

			'password' => '',

			'charset' => 'utf8',




			// use 'site/error' action to display errors








					'levels'=>'error, warning',


				// uncomment the following to show log messages on web pages









	// application-level parameters that can be accessed

	// using Yii::app()->params['paramName']


		// this is used in contact page






	 /** forse dovrebbe essere messa qua


	 * Questo dovrebbe mettere in ogni form un field hidden

     * con un codice in modo da verificare che la richiesta arrivi dal nostr o sito

     * Funziona.









	/** Invece questo dovrebbe evitare di subire degli attachi attraverso i ns cookie













class AlfController extends Controller{


	public function actionFirst($prova="0",$ok="0")



       //print Yii::app()->user->isGuest; //if user prints '1'.



	   $session=new CHttpSession;


	   foreach($session as $name=>$value)

	    print "Session: $name => $value )<br />";



	   $purifier = new CHtmlPurifier();

       $purifier->options = array(

         'HTML.Allowed' => 'p,a[href],b,strong,i,',



	   $model        = new First;

	   $model->prova = (string) $purifier->purify($prova);

	   $model->ok    = (int)    $purifier->purify($ok);


	   $model->prova = (string) $prova;

	   $model->ok    = (int) $ok;




	     $this->render('first', array(








class First extends CFormModel


	public $prova;

	public $ok;


	public function validateAlf($prova,$ok){

	    $this->prova = $prova;

		$this->ok    = $ok;

	    return true;







$this->pageTitle=Yii::app()->name . ' - First Test';






<p>This is the first file by Yii</p>

<br /><br /><br /><br /><br /><br />


print CHtml::link('Link Text',array('alf/first','prova'=>'Athens','ok'=>'1'));

//output: Link Text 

//and in href there is: http(:2slash)vvv-mysite-com/ush/index.php?r=alf/first&prova=Athens&ok=1


<br /><br />


$url = $this->createUrl('alf/first',array('prova'=>'Athens','ok'=>'1'));

print $url;

//output: /ush/index.php?r=alf/first&prova=Athens&ok=1 


<br /><br />

End of page.


RewriteEngine on

# if a directory or a file exists, use it directly

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php

RewriteRule . index.php

Trying to create a link in demos/blog/protected/views/post/_view.php

it prints in his href


and not


as the title.

I dont understand why.

I post the code.

Other question:

add in main.php ‘showScriptName’ => false, the file (index.php) is hidden but the links of all blog project does not work.

May be there is a bug in this version (1.1.10).

<div class="post">

	<div class="title">

		<?php echo CHtml::link(CHtml::encode($data->title), $data->url); ?>

		<br />

		<?php echo CHtml::link("Feedback", array('alf/first', 'prova'=>'Athens','ok'=>'1',)); ?>




	<div class="author">

		posted by <?php echo $data->author->username . ' on ' . date('F j, Y',$data->create_time); ?>


	<div class="content">


			$this->beginWidget('CMarkdown', array('purifyOutput'=>true));

			echo $data->content;




	<div class="nav">


		<?php echo implode(', ', $data->tagLinks); ?>


		<?php echo CHtml::link('Permalink', $data->url); ?> |

		<?php echo CHtml::link("Comments ({$data->commentCount})",$data->url.'#comments'); ?> |

		Last updated on <?php echo date('F j, Y',$data->update_time); 

		//print "<br />".$data->url."<br />";