class ApiVersion extends CBaseUrlRule
{
public function parseUrl($manager,$request,$pathInfo,$rawPathInfo)
{
if (preg_match('%^(api/(\d+))(/(\w+))(/(\d+))$%', $pathInfo, $matches))
{
// $matches[2] is the version and $matches[4] the model
// If it matches we can check the version api and the model
// If it's ok, set $_GET['model'] and/or $_GET['id']
// and return 'apiVx/view'
}
return false;
}
}
Im very lost with how it works, someone could help me?
if i have to implement services I create a controller called api and i create methods like versions v1, v2, v3 some thing of that sort since I dont know your app structure i can not suggest you anything
but you can do a redirect with the following method
So, Im still confused. My API have different parameters depending the action.
/api/view/car?id=xxx
/api/list/cars?city=xxx
…
And I dont know what I need to write in the createUrl function too.
class ApiVersion extends CBaseUrlRule
{
public $connectionID = 'db';
public function createUrl($manager,$route,$params,$ampersand)
{
if ($route==='car/index')
{
if (isset($params['manufacturer'], $params['model']))
return $params['manufacturer'] . '/' . $params['model'];
else if (isset($params['manufacturer']))
return $params['manufacturer'];
}
return false; // this rule does not apply
}
public function parseUrl($manager,$request,$pathInfo,$rawPathInfo)
{
if (preg_match('%^(\w+)(/(\w+))?$%', $pathInfo, $matches))
$url = $match[1] . $match[2]; // BUILD YOUR URL (controllerName/actionName)
$this->redirect(array($url));
}
return false;
}
}