Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Models in other Module

Hello, How can i use a model in other module ?



1.8k
Accepted
answer
edited Oct '14

That depends I have a multi module setup with a Core module where the models are all in. In the module config files I point to that folder for the models. But this means all models are in one place.

modelsDir = ../apps/core/models/

Inside the Module bootstrapper I register the models namespace.

class Module implements ModuleDefinitionInterface
{

    /**
     * Registers the module auto-loader
     */
    public function registerAutoloaders()
    {

        $loader = new Loader();

        $loader->registerNamespaces(array(
            'Shinzou\Account\Controllers' => __DIR__ . '/controllers/',
            'Shinzou\Core\Models' => __DIR__ . '/../core/models/',
            'Shinzou\Core\Controllers' => __DIR__ . '/../core/controllers/',
            'Shinzou\Account\Forms' => __DIR__. '/forms',
            'Shinzou\Core\Library\Mail' => __DIR__ . '/../core/library/Mail/',
        ));

        $loader->register();
    }

Hope this helps...

Regards,

Alex



7.1k

Smal note. If you read about PSR-0, you can make your code shorter :)

$app_root = ''; // directory root of you namespace
$loader->registerNamespaces(array(
            'Shinzou' => $app_root
        ));