i'm trying to do a simple url in the form of controller and seo friendly title, ie:
www.somedomain.com/company/general-electric
i want the request mapped to the company Controller's View action where i'll take the seo-friendly company name - general-electric and query against my company table's seo-friendly-url column for a match
what would the pattern be for this in the url mamanger?
Page 1 of 1
URL Manager confused
#2
Posted 04 March 2011 - 09:22 AM
hi, it'll be something like this
// config
'rules' => array(
'/company/<companyName:\w+>' => 'company/view',
),
// in the controller
public function actionView($companyName) {
// ...
#4
Posted 04 March 2011 - 09:46 AM
nicocin, on 04 March 2011 - 09:29 AM, said:
This should work:
'company/<name:\w+>'=>'company/view',
Inside the actionView() method of your CompanyController use $_GET['name'] to get the company name.
Check out the Guide. It's explained pretty well!
'company/<name:\w+>'=>'company/view',
Inside the actionView() method of your CompanyController use $_GET['name'] to get the company name.
Check out the Guide. It's explained pretty well!
that's exactly what i tried but no luck. I get a system generated 404 saying it can't find the requested action 'company-name'. Meaning it's trying to map the company name to an action.
i have:
'rules'=>array(
'companies'=>'companies/index',
'companies/<seo_url_name:\w+>'=>'companies/view',
then in my view action:
public function actionView()
{
if(isset($_GET['seo_url_name']))
{
$company=Post::model()->find('seo_url_name=?', array($_GET['seo_url_name']));
#5
Posted 04 March 2011 - 10:11 AM
ololo, on 04 March 2011 - 09:22 AM, said:
hi, it'll be something like this
// config
'rules' => array(
'/company/<companyName:\w+>' => 'company/view',
),
// in the controller
public function actionView($companyName) {
// ...
thanks I tried that but no luck. I get a 404 error: The system is unable to find the requested action "general-electric".
#6
Posted 04 March 2011 - 11:19 AM
Got it. The problem was with the regular expression \w+. It only matches on alpha numeric characters. When i changed my rule to this it started working: 'companies/<seo_url_name:[a-zA-Z0-9-]+>'=>'companies/view',
Share this topic:
Page 1 of 1

Help











