Create class instance from variable in Zend Framework

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?

Answers


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.


Need Your Help

How to make web app accessible on the web using WAMP?

php apache web-applications wamp

I've only just installed WAMP Server 2.2 on my computer running Windows 7, in order to build a web app and make it available online. However, I don't have a clue as to how I do this exactly, being a

attributed string which can accept instances depending upon what is passed from a table view

iphone objective-c ios6 xcode4 nsattributedstring

I have a tableView which users will select an instance. I have segue set-up to pass the instance to the textView. I have an NSLog setup so I know the correct data is being passed. I want to setup an

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.