ZF3 route with access to db

376 views Asked by At

I am new to zend framework 3 and I am trying to create a new route type that can search in the database to match the route path. I am using doctrine orm and unfortunately I don't know how to inject the entity manager inside the route class.

I tried defining a factory class for the route to have access to the service manager but that didn't work because the route classes must implement Zend\Router\Http\RouteInterface which states that the route class must contain it's own factory defined as "function factory($options)".

Can anyone please help?

Thank you very much.

1

There are 1 answers

1
tasmaniski On

In the way you ask the question you have to write your custom Router strategy relying on zend-router's interfaces and abstractions. For eg. ZF support different router strategies to match the URL (as in any modern framework) but you need to write the custom router strategy to access the DB and return what controller/action should be executed.

To be honest if you are new to ZF3 maybe try to solve the problem on little bit less advanced way.

Other solution, maybe you can create dynamic router and pass URL_SLUG. Than you will have one action where you will check what content you should load from the DB by URL_SLUG (or any other ID you choose).