I don’t know that you guys are still watching this, but I’ve solved it. So others don’t have to spin their wheels to solve this relatively simple goal, here’s how it’s done.
First, the instructions above were helpful and got me started in the right direction. The problem I had when implemented was if the URL is generated in a CMenu widget, the view was urlencoded, so ‘this/that’ becomes ‘this%2Fthat’ and that mucks up the whole process.
I’ll put all the steps here in detail:
Static pages in subdirectories can be inserted by using ‘view’=>‘test.this’ in the url array, but when using urlmanager, it ends up being /this.that instead of /this/that.
Start by creating the static file in protected/site/pages/this/that.php and create a new menu link, except instead of putting this.that, change it to this/that
$this->widget('zii.widgets.CMenu',array(
'items'=>array(
...
array('label'=>'test', 'url'=>array('/site/page', 'view'=>'this/that')),
...
));
You’ll need to have urlmanager configured to accomplish this:
...
'urlManager'=>array(
// we're going to override urlmanager
'class'=>'UrlManager',
'urlFormat'=>'path',
...
'rules'=>array(
...
'pages/<view:.*>'=>'site/page',
...
),
),
...
As stated earlier, create PagesView.php in protected/controllers:
<?php
class PagesView extends CViewAction {
protected function resolveView($viewPath) {
$viewPath = str_replace('/', '.', $viewPath);
parent::resolveView($viewPath);
}
}
Edit protected/controllers/SiteController.php changing the class of ‘page’ from CViewAction to PagesView
Now, copy CUrlManager.php from your framework/web/ directory into protected/components and rename it to UrlManager.php (the class we configured in the main.php file)
Edit the new UrlManager.php file.
-
rename CUrlManager class to UrlManager
-
Change the class extension for UrlManager from CApplicationComponent to CUrlManager
-
rename CUrlRule class to UrlRule
-
Change the class extension for UrlRule from CComponent to CUrlRule
-
In the UrlManager class, remove ALL properties
-
In the UrlManager class, remove ALL functions except createUrlRule
-
Edit the createUrlRule function , replacing CUrlRule with UrlRule
-
in the UrlRule class, remove ALL properties
-
in the UrlRule class, remove ALL functions except createUrl
-
Edit createUrl:
Find this code:
foreach($this->params as $key=>$value)
{
$tr["<$key>"]=urlencode($params[$key]);
unset($params[$key]);
}
Change it to this:
foreach($this->params as $key=>$value)
{
if($route == 'site/page') {
$tr["<$key>"]=$params[$key];
} else {
$tr["<$key>"]=urlencode($params[$key]);
}
unset($params[$key]);
}
BAM - you’re done
I’ve attached both UrlManager.php and PagesView.php which you can drop right into your protected/components directory.