e-Zest members share technology ideas to foster digital transformation.

Phalcon Working with Multi Modules

Written by Kunal Pingalkar | Dec 12, 2014 3:16:00 PM

Step 1:

kunal@kunal:/var/www/html/p/phalcon$ sh phalcondevtool/phalcon project multimod –type=modules

kunal@kunal:/var/www/html/p/phalcon$ cd multimod

kunal@kunal:/var/www/html/p/phalcon/multimod$ cd apps/

kunal@kunal:/var/www/html/p/phalcon/multimod/apps$ ls

frontend

Step 2:

kunal@kunal:/var/www/html/p/phalcon/multimod/apps$ cp -r frontend/ admin/

kunal@kunal:/var/www/html/p/phalcon/multimod/apps$ ls

admin frontend

kunal@kunal:/var/www/html/p/phalcon/multimod/apps$ cd admin/

Step 3:

kunal@kunal:/var/www/html/p/phalcon/multimod/apps/admin$ sudo vi Module.php

In the above file make changes in namespace and in registerAutoloaders

namespace Multimod\Frontend;

Change to

namespace Multimod\Admin;

And

$loader->registerNamespaces(array(
            'Multimod\Frontend\Controllers' => __DIR__ . '/controllers/',
            'Multimod\Frontend\Models' => __DIR__ . '/models/',
));

Change to

$loader->registerNamespaces(array(
            'Multimod\Admin\Controllers' => __DIR__ . '/controllers/',
            'Multimod\Admin\Models' => __DIR__ . '/models/',
));

Step 4:
kunal@kunal:/var/www/html/p/phalcon/multimod/apps/admin$ cd controllers/
kunal@kunal:/var/www/html/p/phalcon/multimod/apps/admin/controllers$ sudo vi ControllerBase.php

In above file change the namespace.

namespace Multimod\Frontend\Controllers;
Change to
namespace Multimod\Admin\Controllers;

Step 5:
kunal@kunal:/var/www/html/p/phalcon/multimod/apps/admin/controllers$ sudo vi IndexController.php

In above file change the namespace.

namespace Multimod\Frontend\Controllers;
Change to
namespace Multimod\Admin\Controllers;

Step 6:
kunal@kunal:/var/www/html/p/phalcon/multimod/apps/admin$ sudo vi views/index/index.phtml

Add following line in above file to make sure that your admin view is different.

<h1>Congratulations! you are in admin view</h1>

Step 7:
kunal@kunal:/var/www/html/p/phalcon/multimod/config$ sudo vi modules.php

Add new register modules.

 'frontend' => array(
        'className' => 'Multimod\Frontend\Module',
        'path' => __DIR__ . '/../apps/frontend/Module.php'
    )


Add new line below to this is as follow....

'admin' => array(
        'className' => 'Multimod\Admin\Module',
        'path' => __DIR__ . '/../apps/admin/Module.php'
    )


Step 8:
kunal@kunal:/var/www/html/p/phalcon/multimod/config$ sudo vi services.php

You foud the default module is frontend so we need to add the routing for admin module. So here is the code.

$router->add("/admin", array(
                'module'     => 'admin',
                'namespace'  => 'Multimod\Admin\Controllers',
                'controller' => 'index',
                'action'     => 'index',
        ));

URL for front end : http://localhost/p/phalcon/multimod/

URL for Backend Admin : http://localhost/p/phalcon/multimod/admin