2plus
2plus

Reputation: 261

Zend Framwork 2 - Common class

I would like to use a common class file for all the modules. I like to keep all the common variables and arrays in that file.

I had created a folder 'Common' as like as 'Zend' library folder. And created a class Common.php in that folder.

Afterwards, I initialized use Common/Common in controller;

Created an Object

$common = new Common();

It shown an error.

'Class not found Common\Common'.

How can I do this in ZF2?

Upvotes: 0

Views: 255

Answers (1)

Jurian Sluiman
Jurian Sluiman

Reputation: 13558

It is really suggested you step out of monolithic thoughts with Zend Framework 2. Make modules independent and self-contained. This also means you shouldn't let big all-of-a-kind classes floating around in your application.

If you want to have for example a shared logger instance, make a log module your other modules depend on. Same holds for caching, database connections etc. With me will several others really trying to convince people not to use these kind of strategies.

When you give more insights in why you need a "common" class, perhaps more detailed answers can help you with the architectural decision. Personally I would suggest you to look first at your modular architecture instead of trying to solve this specific problem.

PS. Real answer: probably you have an autoloading issue...

Upvotes: 1

Related Questions