<img alt="" src="https://secure.leadforensics.com/150446.png " style="display:none;">
Go to top icon

Phalcon Working with Multi Modules

Kunal Pingalkar Dec 12, 2014

Technology

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

e-Zest is a leading digital innovation partner for enterprises and technology companies that utilizes emerging technologies for creating engaging customers experiences. Being a customer-focused and technology-driven company, it always helps clients in crafting holistic business value for their software development efforts. It offers software development and consulting services for cloud computing, enterprise mobility, big data and analytics, user experience and digital commerce.