Hi all,
I’m trying to set up a dblooked’up controller
currently Yii does the following :
-
analyse the request
-
get the value of the ‘r’ var
-
expand it
-
initialise correct controller with needed action
-> which gives in other terms
-
request : index.php?r=MyController/alert
-
initialize controller MyController with action actionAlert
Now, I would like to add a new routing method which does the following
-
analyze the request
-
get the value of the ‘c’ var (my new routing var)
-
expand it (using db lookup)
-
initialize correct controller with needed action
-> which gives in other terms
-
request : index.php?c=x23/alert
-
perform a db lookup to find correct controller. let’s say x23 is controller MySuperController
-
initialize controller MySuperController with actionAlert
At the end it would do something like this (simplistic but …) :
// index.php?c=x23/alert
if(isset($_REQUEST['c'])) {
$splitRoute = explode('/',$_REQUEST['c']);
// $splitRoute = array('x23','alert');
$splitRoute[0] = Url::dbLookUp($splitRoute[0]);
// $splitRoute = array('MySuperController','alert');
$_REQUEST['r'] = implode('/',$splitRoute);
// $_REQUEST['r'] = 'MySuperController/alert';
}
// ...
// classic Yii routing
To make sure I’m clear about what I want here is how I implemented it in Prado some time ago :
I have a table in a db which link hashes with pages and vars
hash | page | dbData
x26 | contact.php | manager@mail.com
x36 | contact.php | dev@mail.com
x28 | home.php | someData
I created the following classes :
-
XDbUrlManager.php <-> TUrlManager.php (to handle constructUrl, …)
-
XDbUrlMapping.php <-> TUrlMapping.php
-
XDbService.php <-> TPageService.php (XDbService extends TPageService and perform the db lookup)
-
XDbPage.php <-> TPage.php (XDbPage extends TPage and handles properties retrieved through the db lookup)
-
XDbThemeManager.php <-> TThemeManager.php
In the end I use it like this :
index.php?dbpage=x26
-> db lookup which gives :
class contact extends XDbPage {
public function onLoad($param) {
parent::onLoad($param);
// property dbData has been filled during request
// so I can use it to pre-fill a data field
$this->managerEmail->text = $this->dbData;
}
}
If someone is able to give me an idea to create this kind of stuff under Yii, I would really appreciate it.
Thank you