Hi,
I have built a site on Yii/PHP that is mostly static PHP files full of HTML/CSS/js with a little PHP thrown in for integration with enterprise infrastructure. I want clean API-style urls, with no requirement for the user to remember filenames or extensions. I have a config (main.php) that uses the urlRouter as follows:
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
'<alias:search\-results>'
=> 'staticpage/page',
'<alias:contact>'
=> 'site/contact',
'<alias:expertise|technology|services|phpinfo|careers|about|terms\-and\-conditions>'
=> 'staticpage/page',
'<alias:technology\/tv|technology\/md|technology\/oc|technology\/cc|technology\/ag>'
=> 'staticpage/page',
'<alias:careers\/our\-story|careers\/benefits|careers\/what\-people\-say|careers\/job\-openings>'
=> 'staticpage/page',
'<alias:about\/news|about\/blog|about\/mission|about\/board|about\/leadership|about\/global\-perspectives|about\/case\-studies>'
=> 'staticpage/page',
'<alias:about\/leadership\/alec\-eiffel|about\/leadership\/jp\-hackworth>'
=> 'staticpage/page'
),
'showScriptName'=>false,
'caseSensitive' => false,
),
and all of those items point to StaticpageController’s actionPage method. That method does a this->render after retrieving the meta description tag data from the config (main.php).
public function actionPage($alias)
{
$meta_description = Yii::app()->params['pageDescriptions']['all'];
$path = '/site/pages';
switch ($alias) {
case 'search-results':
$meta_description = $meta_description . Yii::app()->params['pageDescriptions']['about'];
$path = '/site';
break;
case 'contact':
$meta_description = $meta_description . Yii::app()->params['pageDescriptions']['contact'];
$path = '/site';
break;
case 'phpinfo':
$meta_description = $meta_description . Yii::app()->params['pageDescriptions']['contact'];
$path = '/site';
break;
case 'terms-and-conditions':
$meta_description = $meta_description . Yii::app()->params['pageDescriptions']['terms-and-conditions'];
$path = '/site';
break;
case 'about':
$meta_description = $meta_description . Yii::app()->params['pageDescriptions']['about'];
$path = '/site/pages';
break;
case 'careers':
$meta_description = $meta_description . Yii::app()->params['pageDescriptions']['careers'];
$path = '/site/pages';
break;
case 'careers/job-openings':
$meta_description = $meta_description . Yii::app()->params['pageDescriptions']['careers/job-openings'];
$path = '/site/pages';
break;
case 'about/leadership':
$meta_description = $meta_description . Yii::app()->params['pageDescriptions']['about/leadership'];
$path = '/site/pages';
break;
default:
$path = '/site/pages';
}
Yii::app()->clientScript->registerMetaTag($meta_description, 'description');
$this->render($path . '/' . $alias);
}
Would love to remove the requirement to edit the config (main.php) file, the StaticpageController, on top of creating the actual new .php file that represents the content at the other end of the url, eg ‘truebadore.com/about/careers’ or ‘truebadore.com/about/leadership/alec-eiffel’
Please do recommend an architecture that can support the above URLs for static page content, as well as more traditional urlRouter type pages like ‘truebadore.com/blog/2013/2/why-yii-is-an-awesome-framework’ or ‘truebadore.com/partners/best-guy/fairfield’
KnowwhatImean?
Thanks!