Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Structure for admin modules
  • I'm really new to Fuel, coming from CI, so maybe this was asked before, but I couldn't find it. I have a modular app where the modules can have a frontend controller, but also the possibility for an admin controller.
    In CI I use HMVC, and some custom routes so that I can have this:
    modules/dashboard/controllers/dashboard_admin.php And then this controller is accessed through /admin/dashboard. Similar to the example from Phil Sturgeon in a blog post some time ago. I was able to achieve something like this in Fuel:
    modules/dashboard/classes/controller/admin.php But this would mean that all my admin controllers would be admin.php, and this just doesn't feel right, since I'm using a quick open function in my editor, and this way it's hard to find the admin controller I want, since all of them are called admin.php ;)
    The problem is with the underscores I guess, cause Fuel uses those for the folder structure. Does anyone have a best practice suggestion for something like this? How do you do it?
    I would appreciate any feedback. Thanks
  • I normally put admin sections, of any size, within a folder. /classes/controllers/blog.php
    /classes/controllers/admin/welcome.php (Dashboard)
    /classes/controllers/admin/blog.php So that would appear as
    /blog
    /admin
    /admin/blog You can, currently, only use one level of folders. See Controller in a subdirectory for more.
    http://fuelphp.com/docs/general/controllers/base.html
  • I think you didn't really understand my problem. I'm using modules so your example wouldn't work here. Thanks for the feedback anyway ;)
  • I do it this way: Routes:
    'admin'      => 'dashboard/admin/home',
    'admin/(:segment)/(:any)' => '$1/admin/$2',
    

    Structure:
    modules/dashboard/classes/controller/admin/home.php // site_url/admin
    modules/dashboard/classes/controller/admin/something.php // site_url/admin/dashboard/something
    modules/blog/classes/controller/admin/ea.php // site_url/admin/blog/ea/param
    

    I don't really like that many subfolders, but it's the best way I found.
  • Hm, this seems a little better, but is it even possible to create a structure like this:
    modules
        dashboard
            classes
                controller
                    admin
                        dashboard.php
                    dashboard.php
    

    This way there would be 2 classes called Controller_Dashboard in the same namespace, so I guess it would throw an error.
    I don't know if you know how the quick open work in Coda. Let's say I want to work on the blog module of a huge project, and I don't wanna klick through the files manually, so I press ctrl+q, type blog, and I have 2 files there. blog.php and blog_admin.php. That's the way I have it setup in CI.
    I know this is not CI, but I think it would be good have a good solution for this, since almost all apps have an admin area, and it is much nicer to work with modules ;) Well I guess i could call the 2 controllers dashboard.php and dashboardadmin.php, but that just looks ugly. A shame you can't use underscores.
  • If I remember correctly I did mine like this...
    modules
        dashboard
            classes
                controller
                    admin
                        > admin.php
                    dashboard.php
    

    Then I can call the admin with "/dashboard/admin" Instead of something like "/dashboard/admin/dashboard"
    namespace Dashboard;
    
    class Controller_Admin_Admin ... {}
    
  • Why not simple:
    modules
        dashboard
            classes
                controller
                    admin.php
                    dashboard.php
    

    So you don't need the subfolder. But this isn't really what I'm looking for, since all my admin controllers would be admin.php, and I'm trying to avoid that.
  • You can use routing to route requests for
    'admin/(:any)'      => '$1/admin/???'
    
    ? Or whatever name you want for your admin controller?
  • Yes, but I need a subfolder then. Well I guess this is the best possible solution.
    modules/blog/classes/controller/blog.php
    modules/blog/classes/controller/admin/blog.php
    

    Thanks

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion