Detect request path in Module

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Detect request path in Module

Norbert Máté
Hi all,
  I want to detect if the request is for a module and setup some thing only
that case. I have found a solution:

$matched = $router->match($request);
  if ($matched && $matched->getMatchedRouteName() == 'rest-api')

My problem with this is that it detects the route and not the module. If I
have to setup things for all the functions in a module than I will have to
add here all the routes.

Is there a better way?
Thanks.

Regards,
Norbert.
Reply | Threaded
Open this post in threaded view
|

Re: Detect request path in Module

weierophinney
Administrator
On Thu, Jul 18, 2013 at 9:01 AM, Norbert Máté <[hidden email]> wrote:

>   I want to detect if the request is for a module and setup some thing only
> that case. I have found a solution:
>
> $matched = $router->match($request);
>   if ($matched && $matched->getMatchedRouteName() == 'rest-api')
>
> My problem with this is that it detects the route and not the module. If I
> have to setup things for all the functions in a module than I will have to
> add here all the routes.
>
> Is there a better way?

Yes -- use events!

Here's an example: https://gist.github.com/weierophinney/6030213

Essentially, you listen to the "route" event, after routing has
occurred. If the matched controller has the same namespace as your
module, you do something.

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Detect request path in Module

Norbert Máté
Thank you.

Regards,
Norbert.


On 18 July 2013 18:23, Matthew Weier O'Phinney <[hidden email]> wrote:

> On Thu, Jul 18, 2013 at 9:01 AM, Norbert Máté <[hidden email]>
> wrote:
> >   I want to detect if the request is for a module and setup some thing
> only
> > that case. I have found a solution:
> >
> > $matched = $router->match($request);
> >   if ($matched && $matched->getMatchedRouteName() == 'rest-api')
> >
> > My problem with this is that it detects the route and not the module. If
> I
> > have to setup things for all the functions in a module than I will have
> to
> > add here all the routes.
> >
> > Is there a better way?
>
> Yes -- use events!
>
> Here's an example: https://gist.github.com/weierophinney/6030213
>
> Essentially, you listen to the "route" event, after routing has
> occurred. If the matched controller has the same namespace as your
> module, you do something.
>
> --
> Matthew Weier O'Phinney
> Project Lead            | [hidden email]
> Zend Framework          | http://framework.zend.com/
> PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
>
> --
> List: [hidden email]
> Info: http://framework.zend.com/archives
> Unsubscribe: [hidden email]
>
>
>