Yaf_Router::addRoute is not a static method.
you should do like:
$dispatcher->getRouter()->addRoute("regex", $route); //http://www.php.net/manual/en/yaf-dispatcher.getrouter.php
btw: when you in development environ, it is useful to keep error_reporting on and look at error_log when you get some problems :)
thanks
--
Laruence Xinchen Hui
http://www.laruence.com/
2011/11/30 Eduárd Moldovan <ed@xxxxxxxx>
Hey Laruence,
I have tried the below example, but did not really get it work.
My code looks like this:"controller" => "index",public function _initRoute(Yaf_Dispatcher $dispatcher) {
$route = new Yaf_Route_Regex (
"#(.*)#",
array(
"action" => "index",
),
array(
1 => "test",
)
);Yaf_Router::addRoute ('regex', $route);
}
Any ideas about what I am doing wrong?
Thx,
edi--2011/11/28 Laruence <laruence@xxxxxxx>
HI:
Yaf designd a route statck to proviods the ability for extends route process.
you can add new route into stack by calling
Yaf_Router::addRoute(or addConfig),
when a request coming , Yaf will call the top route in the stack at
the first time, as pseudo codes like:
while ($route = pop($stack)) {
if ($route->route($request) == TRUE) {
return FINISH.
}
}
there are two routes defined by Yaf are always return TRUE, that
are Yaf_Route_Simple and Yaf_Route_Static.
so according your question, the easiest way is reigster a
Yaf_Route_Simple route with no-sence parameters, then all the request
will be routed to default controller and default action.
and also you can use Yaf_Route_Regex, it is the most felixible
route in Yaf: http://www.php.net/manual/en/yaf-route-rewrite.construct.php
the first argument for Yaf_Route_Regex::__construct is used to match
a uri, if the uri doesn't match this value, then the Yaf_Route_Regex
will don't route this request, just simple return FALSE, so we
can register a Regex route at the Bootstrap like:
public function _initRoute(Yaf_Dispatcher $dispatcher) {
$route = new Yaf_Route_Regex (
"#(.*)#",
array(
"controller" => "product",
"action" => "info",
),
array(
1 => "test",
)
);
$router->addRoute('regex', $route);
}
see the code above, we set the first argument to Yaf_Route_Regex a
value : "#(.*)#", which means this route will match any request-uri.
then we can assign any controller/action pair for this route
result in the second argument.
the last argument means, the first captrue in the regex pattern
will be named "test" in the $request::_$params, that is you can access
this value by calling $request->getParam("test").
I have updates some new docs at php.net, but it need a little time
to show up. and I will keep updating :)
PS: I am going to cc this mail to php-generall list, then if any
other people have the sampe question, they will find this :)
thanks very much for you interesting of Yaf :)
2011/11/28 Moldován Eduárd <ed@xxxxxxxx>:
> Oh, I forgot something. An example of a complete application.ini and ways to
> get the config values with YaF would be great!
> Thx ahead,
> edi
>
>
>
> 2011.11.27. dátummal, 14:49 időpontban Laruence <laruence@xxxxxxx> írta:
>
> HI:
> I have update some new docs into Yaf doc(php.net), but it will take a
> little time to show up.
> and sure, could you give me some specific questions? I will answer you
> :)
> also, I will add some new examples soon :)
> thanks very much for your interesting of Yaf
> :)
> 2011/11/27 Moldován Eduárd <ed@xxxxxxxx>
>>
>> Hey there,
>>
>> I started working a bit with YaF, but it looks like the documentation is
>> very rare. Could you tell me please where any documentation can be found on
>> routing?
>> Any example maybe?
>> I would actually welcome any kind of documentation, on any part of YaF
>> (Except what I already found on php.net and code.google.com).
>>
>> Thx,
>> edi
>>
>> --
>> <logo.png> Moldován Eduárd
>> boxed.hu
>> ed@xxxxxxxx
>> +36 30 691 2 691
>> skype: edimoldovan
>
>
> --
> Laruence Xinchen Hui
> http://www.laruence.com/
>
--
Laruence Xinchen Hui
http://www.laruence.com/
Moldován Eduárd
Laruence Xinchen Hui
http://www.laruence.com/