Question

I'm building a Zend Framework application and created some controllers which correspond to database tables and hold methods for performing CRUD operations on those tables.

I've just started working on the Companies controller which holds methods for adding, editing and deleting companies. For this we can use the traditional controller/action URL pattern:

http://example.com/companies/add
http://example.com/companies/edit/some-company

The problem is that for each Company we also need to manage its Contacts and Machines:

http://example.com/companies/some-company/machines/add
http://example.com/companies/another-company/contacts/edit/some-contact

I just can't get my head around how to manage this in Zend Framework. Should I 'nest' the controllers through routing, or should I make use of modules? Any help would be very much appreciated.

Was it helpful?

Solution

You could easily write custom routes to handle this. For example, this:

http://example.com/companies/some-company/machines/add

would become in your .ini file:

routes.machine.route = "companies/:companyname/machines/:action"
routes.machine.defaults.controller = machines
routes.machine.defaults.action = index 

This will point the url to the machines controller and sets companyname as a GET-var.

You can easily change this to suit any form you like.

OTHER TIPS

with zend framework default router , your url's didn't work. this links must work:

 http://example.com/companies/add
 http://example.com/companies/edit/id/some-company
 http://example.com/companies/addmachines/id/some-company//
 http://example.com/companies/contacts/mod/edit/companyid/another-company/

format:

http://yoursite.com/Module(if available)/Controller/Action/param1/val1/param2/val2/?param3=val3
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top