1
votes

I am learning Zend Framework 2 as it seems to be quite interesting. Unfortunately I can't find a good book to teach my self the framework.

I am interested in knowing which class/object is used to generate links. Lets take some examples:

  1. Module M has controllers C and actions A1 and A2, assume I am in the view of A1 and am needing to put a link to the controller A2?
  2. Module M has controllers C1 and C2. From the C1A action of C1, how can I generate a link to C2's C2A action?
  3. Got 2 modules, Module M1 and Module M2. Both modules have controllers M1C and M2C respectively and each having index actions. From the index controller of M1C (first module), how can I make a link to M2C (of the second module) ?

I am following the Zend Skeleton Application. I wanted to create a link from Application module - Layout view to another view in another module. Well it is a menu item link.

I think the above 3 scenarios will cover most of such links.

I think routing should play a role in this. Not sure.

3

3 Answers

1
votes

As Sam said, what you are looking for is the Url view helper. If you look in the Zend Skeleton Application's configuration file, you will see that there is a convenient route for this.

To generate a URL to a given action within the Application module, you should be able to do like this:

echo $this->url('application/default', array(
    'controller' => 'MyController',
    'action' => 'MyAction',
));

This route is for the Application module, but you could create a similar route for any other module and then still do as above. The first parameter is the name of the route. You can reference child routes with the URL view helper; before the slash is the parent route and after the slash is the name of the child route. I guess you could also create a generic route which also takes the module name as a parameter (segment).

As for finding a book, I bought this book by Michael Romer. I never finished it, but what I read of it was good, although there were quite a few grammar mistakes, but I presume that those are fixed by now. Either way, that book would be a safe bet I'd say.

Best of luck!

0
votes

Try to work yourself through the UserGuide.

You want also to take a closer look at the Zend\View\Helper\Url

0
votes

Let me suggest you the "Using Zend Framework 2" book available here: http://leanpub.com/using-zend-framework-2 Use this coupon for 90% discount: DI$COUNT