0

So I have a setup of the Zend Framework 2 skeleton, and I want to add a class that I have made, file.class.php , and I want to use it in an action controller.

  1. Where should this file go?
  2. Can I set an autoload? I don't want to use require_once in my action
Ronak Patel
  • 390
  • 1
  • 3
  • 12
Uffo
  • 9,628
  • 24
  • 90
  • 154

2 Answers2

0

in your Bootstrap add the following to the _initAutoload():

 Zend_Loader_Autoloader::getInstance()->registerNamespace('name');

Zend Framework: Autoloading a Class Library

Community
  • 1
  • 1
Ronak Patel
  • 390
  • 1
  • 3
  • 12
0

The best way is to respect the PSR-0 standards:

You can add your file to /module/Application/src/Application/Service/Classname.php Add the correct namespace and classname to your file:

<?php
namespace Application\Service;

class Classname
{
}

You can then use it in your controller as:

$obj = new Application\Service\Classname;

There are even better ways to add code to ZF2, check out this good introduction to the ServiceManager.

mihaidoru
  • 327
  • 2
  • 10