Yii Framework Forum: Routes Problem - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Routes Problem Rate Topic: -----

#1 User is offline   ville 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 10-June 13

Posted 16 June 2013 - 02:18 PM

Hey,

How should I configure the rules in config/main.php in order to have url-structure like this:

index.php/category/products/2

Right now I'm getting urls like this index.php/category/products/id/2 using CHtml::link()-method:

echo CHtml::link($model->name, $this->createUrl('index.php/category/products', array('id' => $model->id))

So how can I get rid of that last "id" parameter?

Thanks in advance.
0

#2 User is offline   KonApaz 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,317
  • Joined: 21-February 11
  • Location:Greece

Posted 16 June 2013 - 02:54 PM

Hi @ville

explain us what are category and products ( controller and action ?)
Also post your urlManager's rules

In addition, did you check something like that ?
'<controller:\w+>/<controller:\w+>/<id:\d+>' => '<controller>/<action>',

Yii is the best php framework in the world!
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

#3 User is offline   ville 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 10-June 13

Posted 16 June 2013 - 03:02 PM

Hi,

category refers to a controller and this controller has an action called products. At the moment I have default rules in config/main.php.

		
'urlManager'=>array(
			'urlFormat'=>'path',
			'showScriptName'=>false,
			'caseSensitive'=>false,
			'rules'=>array(
				'<controller:\w+>/<id:\d+>'=>'<controller>/view',
				'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',		
				'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
			),
		),

0

#4 User is offline   Tsunami 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 150
  • Joined: 16-February 12

Posted 16 June 2013 - 03:17 PM

index.php is not part of a route.

echo CHtml::link($model->name, $this->createUrl('category/products', array('id' => $model->id))

0

#5 User is offline   KonApaz 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,317
  • Joined: 21-February 11
  • Location:Greece

Posted 16 June 2013 - 03:20 PM

View PostTsunami, on 16 June 2013 - 03:17 PM, said:

index.php is not part of a route.

echo CHtml::link($model->name, $this->createUrl('category/products', array('id' => $model->id))



I agree with @Tsunami
I didn't see that!

check also the documentation
http://www.yiiframew...1/en/topics.url
Yii is the best php framework in the world!
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

#6 User is offline   ville 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 10-June 13

Posted 16 June 2013 - 03:28 PM

Thanks,

so far I haven't got rid of index.php from the url. I have read Yii documentation and several topics here but none of them have offered a solution.
My .htaccess-file is located inside protected-directory with the following content:

deny from all
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


Besides these, apache Mod rewrite is enabled and there is no other .htaccess in parent folder which would conflict maybe.
0

#7 User is offline   ville 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 10-June 13

Posted 16 June 2013 - 03:35 PM

View Postville, on 16 June 2013 - 03:28 PM, said:


My .htaccess-file is located inside protected-directory with the following content:



This was the problem I guess, it should have been in the document root, not in protected-directory. Works now.
0

#8 User is offline   Tsunami 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 150
  • Joined: 16-February 12

Posted 16 June 2013 - 03:36 PM

The .htaccess in the protected folder is there for a reason though, make sure to put the original back.
0

#9 User is offline   KonApaz 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,317
  • Joined: 21-February 11
  • Location:Greece

Posted 16 June 2013 - 03:38 PM

View Postville, on 16 June 2013 - 03:28 PM, said:

Thanks,

so far I haven't got rid of index.php from the url. I have read Yii documentation and several topics here but none of them have offered a solution.
My .htaccess-file is located inside protected-directory with the following content:

deny from all
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


Besides these, apache Mod rewrite is enabled and there is no other .htaccess in parent folder which would conflict maybe.


why your htaccess has all of them? the official generated htaccess by yii has only "deny from all"
Do you want more protection? then this file have to moved in root folder, don't forget to has also one .htaccess in protected folder with "deny from all"
Yii is the best php framework in the world!
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users