php - Routing requests to module -
php - Routing requests to module -
hi im looking info on best way route requests custom module in yii framework.
i implementing restful api project , hoping there way route requests api/ module rest api lives. improve away how route api requests custom urlmanager class extends curlmanager in module deals routes. request mydomain/api/user/model deferred , handled urlmanager component in module , other requests ie mydoamin.com/client/create handled normal yii applicaton. far can tell isnt possible!!
so settle definig url manager class in config catches api routes so
class urlmanager extends curlmanager { protected function processrules() { if(!isset($_get['r'])) { $this->seturlformat('path'); $this->showscriptname=false; $this->rules=array( //api rest patterns array('api/list', 'pattern'=>'^api/user/<model:\w+>', 'verb'=>'get'), array('api/view', 'pattern'=>'^api/user/<model:\w+>/<id:\d+>', 'verb'=>'get'), array('api/update', 'pattern'=>'^api/user/<model:\w+>/<id:\d+>', 'verb'=>'put'), array('api/delete', 'pattern'=>'^api/user/<model:\w+>/<id:\d+>', 'verb'=>'delete'), array('api/add', 'pattern'=>'^api/user/<model:\w+>', 'verb'=>'post'), array('api/test', 'pattern'=>'^api/user/test/<model:\w+>'), array('api/login', 'pattern'=>'^api/user/<model:\w+>/login'), array('api/logout', 'pattern'=>'^api/user/<model:\w+>/logout'), // other controllers '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>', '<controller:\w+>/<action:\w+>'=>'<controller>/<action>', '<action:\w+>'=>'site/<action>', ); } homecoming parent::processrules(); } }
my question then, how route request controller in module? ie module/restapi/controller/userapicontroller.php
array('modulecontroller/action' , pattern=>'api/user/<model>' , 'verb'=>'get)
i thought this
'controllermap' => array( 'api'=>'application.modules.restapi.components.apimanager', ),
but im pretty need 2 points of access, 1 dealing admin tasks on api , 1 users, controller construction looks like:
restapicontroller userapicontroller (extends restapicontroller) adminapicontroller (extends restapicontroller)so if there way dynamically route actions kid controllers might work? hope haven't been confusing here hope of yii masters can help problem!!
thanks in advance
i might have misunderstood question (so right me if did), can't utilize normal urlmanager 'normal' rules configured so:
'rules' = array( //api rest patterns array('restapi/userapi/list', 'pattern'=>'^api/user/<model:\w+>', 'verb'=>'get'), array('restapi/userapi/view', 'pattern'=>'^api/user/<model:\w+>/<id:\d+>', 'verb'=>'get'), array('restapi/userapi/update', 'pattern'=>'^api/user/<model:\w+>/<id:\d+>', 'verb'=>'put'), array('restapi/userapi/delete', 'pattern'=>'^api/user/<model:\w+>/<id:\d+>', 'verb'=>'delete'), array('restapi/userapi/add', 'pattern'=>'^api/user/<model:\w+>', 'verb'=>'post'), array('restapi/userapi/test', 'pattern'=>'^api/user/test/<model:\w+>'), array('restapi/userapi/login', 'pattern'=>'^api/user/<model:\w+>/login'), array('restapi/userapi/logout', 'pattern'=>'^api/user/<model:\w+>/logout'), // other controllers '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>', '<controller:\w+>/<action:\w+>'=>'<controller>/<action>', '<action:\w+>'=>'site/<action>', )
i'm pretty sure should work (not exclusively sure camelcasing though). route module action beingness '<moduleid>/<controllerid>/<actionid>'
, know sure because used more once.
php yii url-routing
Comments
Post a Comment