1

I want to be able to build a small app (e.g. a basic login MVC structure) and structure my Phalcon project such that I can just drop it in one folder and tweak the config file a bit.

E.g. I have my basic login app built from the Vokuro tutorial. Now rather than copying controllers to one directory, models to another, etc in order to deploy it in my existing app I want to drop it into a folder (e.g. app/extensions/security) and then tweak my main config/bootstrap so that the requests for Users or Profiles are directed to the controllers in app/extensions/security/controllers.

Everything is namespaced according to the folder structure and my current loader looks like:

$loader->registerNamespaces(array(
    'Me\Controllers' => $config->application->controllersDir,
    'Me\Models' => $config->application->modelsDir,
    'Me\Forms' => $config->application->formsDir,
    'Me' => $config->application->libraryDir,
    'Me\Security' => $config->application->extensionsDir . 'security/'
));

Basically - how do I make Phalcon look in app/controllers for some controllers and in another directory for others (app/extensions/security/controllers)?

I am not sure if this is explained sufficiently well - if clarification is needed, please tell me.

Edit

I've got the login page showing by adding this to my routes

$router->add('/session/:action', array(
    'namespace' => 'Me\Security\Controllers',
    'controller' => 'Session',
    'action' => 1
));

So I think I will create a routes file in my app/extensions/security folder and then load that in the main bootstrap file.

3
  • Do you have namespaces set in your router? Aug 12, 2015 at 15:37
  • I've just tried that and got things going, thanks. I think a routes file for each extension is probably the way to go that is then loaded by the main bootstrap file.
    – Kvothe
    Aug 12, 2015 at 15:48
  • @JamesFenwick Any idea about an easy way to make those controllers find the correct view files? At the moment I'm thinking about putting the details into the extension specific config file.
    – Kvothe
    Aug 12, 2015 at 15:58

1 Answer 1

2

It might be a good idea to move to a multi module application. I explained how I did it at Phalcon Multi-Module Routing.

You would be able to set all the routes, view directories, separate configs, etc. for your security module in one place.

It is fine to extend from your security base class, you already extend from Phalcon\Mvc\Model so it's no different.

You could do something like this:

<?php
namespace My\Controllers;

use My\Security\Controllers\ControllerBase as SecurityBase;

class ControllerBase extends SecurityBase
{
... 
1
  • Thanks, going to take a look at that now. After a quick look I have one question though - would this make it possible for classes in one module to inherit from classes in another module? Every class in the main app should inherit from the ControllerBase in the security module as that implements the Auth / ACL checks.
    – Kvothe
    Aug 12, 2015 at 16:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.