Call to a member function getparam() on a non-object in zend

I am trying to call a function of my module A from another module B. I did this by creating an instance of controller of module A in controller of module B. Though I can call this function, it is unable to access any function with get at its start like getServiceLocator , getRequestUri.

zend framework2 - Call to a member function get() on a non-object in ZF2 - Stack Overflow

All these errors come when I try to work across modules and not on a single module. How should I deal with this? Similarly, I can't use getRequestUri.

call to a member function getparam() on a non-object in zend

A Controller is an agent where it delegates the information from the request to the model layer. The result of this a command or query is via the view returned to the client. If you want to reuse logic, you do that often in the model layer, not in the controllers.

Do not instantiate a controller yourself. For code reusability, it is better to have the domain logic in your domain.

The easiest now is to create a service layer:. Now you can make your ChatController dependent on the ChatService. You can inject the service in your controller:.

All you need now is to register the chat service in the service manager and register a factory for the controller. Now, if you have a FooModule which requires some logic from the ChatModule, create a factory for that Foo controller, inject the chat service and you are done.

By posting your answer, you agree to the privacy policy and terms of service. Stack Overflow Questions Developer Jobs Documentation beta Tags Users. Sign up or log in to customize your list. Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us.

Log In Sign Up. Join the Stack Overflow Community.

Zend Forums • Information

Stack Overflow is a community of 7. Join them; it only takes a minute: Call to a member function get on a non-object in ZF2 Ask Question. Are you saying you're directly instantiating a controller instance inside another controller class? By using a new ControllerA inside ControllerB class? I added some code JurianSluiman. Do let me know if you need something more specific.

Can you explain why you want to instantiate the ChatController?

استدعاء الميثود بالمشاركة - 2 - call by sharing (reference)

What is the use case, what problem are you trying to solve. There is probably a better way to do it than this. The easiest now is to create a service layer: You can inject the service in your controller: Can I call ChatController function from Service Layer?

zend framework2 - How to pass parameter from View Helper (widget) to action? - Stack Overflow

Please read my answer again: Reuse the code in another layer. Giving it a try! Thanks for all the guidance.

zend framework2 - Call to a member function get() on a non-object in Controller - Stack Overflow

And I get the same error as before when I try this. Basically, my domain logic needs access to database, so I need to use these functions. You are on the right track. It is correct you need to fetch the service locator again. If you want to know why, read a blog post I wrote a while back juriansluiman.

Sign up or log in StackExchange. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name.

Stack Overflow works best with JavaScript enabled. MathOverflow Mathematics Cross Validated stats Theoretical Computer Science Physics Chemistry Biology Computer Science Philosophy more 3. Meta Stack Exchange Stack Apps Area 51 Stack Overflow Talent.

inserted by FC2 system