1

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.

Calin
  • 53
  • 1
  • 5

1 Answers1

0

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).

tasmaniski
  • 4,767
  • 3
  • 33
  • 65
  • Thank you for the reply and sorry for the late response. The reason I need the db connection in the router is because of SEO purposes the client want full control of the route url. I tried to overwrite the router class but I couldn't make it work. I am willing to try a custom strategy but I did not find any documentation on how to do that. Can you please help me with some links or some code snippets? Thank you very much. – Calin Aug 25 '17 at 19:26