Unclean Url In Yii

I have an old site. I ported it to yii. On the old version of the site url look like:

example.com/?item=523

example.com/?category=523

example.com/?category=523&sort=rel

Is it possible to use the same path in the framework, yii?

Hi and welcome to Yii!

Yes you can usr UrlManager compined with some other methodologies

Check first, these posts

http://www.yiiframework.com/forum/index.php/topic/44009-forbidden-in-url-containing-signin-word-solved/page__p__208693__fromsearch__1#entry208693

http://www.yiiframework.com/forum/index.php/topic/44437-seo-unique-urls/page__p__210515__fromsearch__1#entry210515

http://www.yiiframework.com/forum/index.php/topic/44433-beautiful-urls-with-slug/page__p__210495__fromsearch__1#entry210495

and the official documentation of Yii

http://www.yiiframework.com/doc/guide/1.1/en/topics.url

After of that I think you will understand how you achieved that.

if however could not make it, Someone (or Ι) in this thread will help you :)

Thank you KonApaz!

I looked the posts, but they are not similar at my problem.

My problem is the "question mark". I did not put my finger in the pattern

It’s not works.


'rules'=>array(

array('/item/index', 		'pattern'=>'?item=<id:\d+>'),

array('/item/index', 		'pattern'=>'\?item=<id:\d+>'),

array('/item/index', 		'pattern'=>'item=<id:\d+>'),

),

I would definitly rerwite it to float more with the yii MVC structure, but its doable if thats not an option.

Your urls will all point to index.php, and you could write the SiteController::actionIndex() to somerhing like this:

<code>

Public function actionIndex()

{

If(isset($_GET(‘item’)) {

$this->redirect(array(‘item/view/’.$_GET(‘item’)));

}

// and so on

}

</code>

I think this would work, but im currently stuck on a galaxy tab.

Let me know if you have any progress, ill be on a computer later.

Good luck

Your URL is not more complex. It is very simple. Your should not configure URL Manager to handle it. This functionality is default provided by scripting language.

All values sending by URL using GET method can be easily catch by simple PHP script global variable.

So, in Yii Framework you can catch is as follow:




class SiteController extends Controller {

  ...

  public function actionIndex() {

	if(count($_GET) > 0) {

  	if(isset($_GET['category']) and intval($_GET['category']) > 0) {

    	// @todo: Do your job here

  	}

	}

  }

  ...

}



First you needed to add the following line to the .htaccess file in your base directory:


RewriteEngine on


RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?param=$1

Then you can access that param by $_REQUEST[‘param’] in the index action


public function actionIndex(){

    if(isset($_REQUEST['param'])){

       //your code here

    }

}

Then you can use the urls as www.example.com/new-category. Then it will get in the $_REQUEST[‘param’]