Creating a URL Hierarchy

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.

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

Find the ‘// application components’ array (‘components’=>array…).

Add the following ‘rules’ to ‘urlmanager’:








Let me know how you get on :)

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, then you need a configuration for the url manager like this:








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'));