Jump to content
Larry Ullman's Book Forums

Conflict With Slugs And Modules

Recommended Posts

Hey guys,


I created a controller 'PageController.php' with a default action 'actionShow' like this:

public function actionShow( $slug = '' ) {

  if ( empty( $slug ) ) {
    $model=Pages::model()->findByAttributes( array( 'slug' => 'accueil' ) );
  else {
    $model = Pages::model()->find('slug = :slug', array(':slug' => $slug));

  if($model===null) {
    throw new CHttpException(404,'The requested page does not exist.');

$this->render('page', array(
  'model' => $model,
  'slug' => $slug,

Then I created a module (and this is where things got problems) called "admin", and declared it in config/main.php


And I set up the urls in config/main.php like that:

    '<module:\w+>/<controller:\w+>/<action:[0-9a-zA-Z_\-]+>/<id:\d+>' => '<module>/<controller>/<action>',
    '<module:\w+>/<controller:\w+>/<action:[0-9a-zA-Z_\-]+>' => '<module>/<controller>/<action>',
    '<module:\w+>/<controller:\w+>' => '<module>/<controller>/index',
    '<slug:\w+>'=> 'page/show',

The problem is when I call the page : maydomain.com/admin, it been processed as a slug for the page and not as a module, I fixed in the actionShow by :


if $slug=='admin'



Is there is a way more clean than this ?

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...