0

i have class Plugin_Magazine extends Zend_Controller_Action

in some views i need to call static function test() from it.

in view i do folowing:

$class_name = 'Plugin_'.$plugin;
$class_name::test();

as a result i have

Catchable fatal error: Argument 1 passed to Zend_Controller_Action::__construct() must be an instance of Zend_Controller_Request_Abstract, none given

but, if i create class Plugin_Magazine w\o extends all works fine.

question is: can i somehow do what i need or just forget about inheritance?

3
  • First question is: why is a call to a static method resulting in a call to the constructor? Commented Dec 1, 2011 at 11:42
  • problem solved with call_user_func(array($controller_name, 'test')) Commented Dec 1, 2011 at 12:06
  • Mark your answers as solved then and write an answer, don't post it there as it's still open. Commented Dec 1, 2011 at 15:03

1 Answer 1

1

You need to pass a Request object to the constructor of the Action class

At somepint your doing this:

 $pm = new Plugin_Magazine();

But you need to pass the request object:

 $pm = new Plugin_Magazine($this->getRequest());

As for this call:

$class_name = 'Plugin_'.$plugin;
$class_name::test();

Why do you need a static function in an Action? This doesn't seem right, if it's reusable logic that exists in an Action that it should be moved elsewhere to where it can be used more easily, like into a Model.

Sign up to request clarification or add additional context in comments.

1 Comment

actually static or public will be test() doesn't matters. tried to do $plugin = new Plugin_Magazines($this->getRequest()); Plugin by name 'GetRequest' was not found in the registry

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.