Yii Framework Forum: Creating a URL Hierarchy - Yii Framework Forum

Jump to content

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

Creating a URL Hierarchy Would like to create a logical hierarchy of URLs Rate Topic: -----

#1 User is offline   queej 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 71
  • Joined: 04-February 10

Posted 05 February 2010 - 08:02 PM

I have a number of objects that I would like to present in URLs as a hierarchy. For example, I would like to map the following:

  • CoursePage => /course/page
  • CourseResource => /course/resource
  • CourseCertification => /course/certification


I'm sure this is possible, but I can't quite follow the documentation and have seen no examples. I'm not sure where I would need to set this, and what to set. I am not sure what is meant by a "route".

Any help would be appreciated.
0

#2 User is offline   outrage 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 313
  • Joined: 10-November 09
  • Location:Blackpool, United Kingdom

Posted 06 February 2010 - 10:45 PM

Try adding this to the /config/main.php file:

Find the '// application components' array ('components'=>array...).

Add the following 'rules' to 'urlmanager':

'urlManager'=>array(
	'rules'=>array(
		'CoursePage'=>'course/page',
		'CourseResource'=>'course/resource',
		'CourseCertification'=>'course/certification',
	),
),


Let me know how you get on :)
0

#3 User is offline   queej 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 71
  • Joined: 04-February 10

Posted 08 February 2010 - 07:24 PM

Thank you. I tried that, with various permutations on the case of the letters, but always get the message:

Unable to resolve the request "course/page".
0

#4 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 09 February 2010 - 03:09 AM

View Postqueej, on 08 February 2010 - 07:24 PM, said:

Thank you. I tried that, with various permutations on the case of the letters, but always get the message:

Unable to resolve the request "course/page".


If you want to access your course/page action by the url http://site.com/CoursePage, then you need a configuration for the url manager like this:

'urlManager'=>array(
    'urlFormat'=>'path',
    'showScriptName'=>false,
    'rules'=>array(
        'CoursePage'=>'course/page',
    ),
),


Also you'll need to edit .htaccess:
Options +FollowSymLinks
IndexIgnore */*
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


Now you can generate links in your application using CHtml::link():

echo CHtml::link('Course page', array('/course/page'));

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