Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Folder structure for multiple apps
  • This is just a suggestion for discussing here in the forums. I don't know if the FUEL team already discussed between them, but since this is a community driven framework I'll just drop some ideas here. I'm really new to FUEL, I've been doing my developments with CI2.0 and I like it very much though it has some limitations which, to my opinion and what I've read about FUEL, are more or less 'fixed' with FUEL, so I wanted to give it a try. I like the folder structure very much as it makes a really good separation between what's supposed to be public and what's not. Kudos for that! IT's also much clearer from what CI has getting rid of helpers and other things that just doesn't add any real value and just complicates the understanding of the framework. I recently ran into a problem getting FUEL to run in a Zend Server (which I didn't solve by the way http://fuelphp.com/forums/topics/view/236) which led me to install it on an xampp distro. That got me into thinking about Hosting services (yes, I don't quite see the connection but my mind works in mysterious ways hehe) and what I found is that FUEL is perfect for having multiple applications using the same "core", thus avoiding multiple copies of the framework. This, at the moment, is not done just right away, some minor changes must be made and that's what this post is all about (I know, a bit of a long introduction but it's for clarity's sake). Right know the folder structure looks like this:
    - /
      |- fuel
      |- public
    
    All magic happens in the fuel folder; public is just there to publish the required assets so that you won't have to deal with them in the .htaccess with a RewriteRule (like one has to do when using CI); so I won't be focusing this on the public folder. The fuel directory is structured separating the 'core' (which make all of FUEL work), a 'packages' folder (which I'll cover later on) and the 'app' folder. Just by the name one knows that we should not mess around the core folder, it's the core and so it should stay: unmodified. Here comes the pourpose of all this: the app folder contains the developed application. Good! But, what if I wan't to have multiple applications running in my Hosting Service? I mean completely unrelated applications? Well out of the box one would have to create a second fuel folder to host the second application. But what if instead of an app folder there would be an apps folder? A container for multiple apps! This isn't done very hard, just rename the app folder to apps folder and copy all it's contents to a new sub-folder with the name of the app. So we could have this:
    - /fuel
      |- apps
            |- my_awesome_app
                 |- cache
                 |- classes
                       ...
            |- my_other_ awesome_app
                 |- cache
                 |- classes
                       ...
      |- core
      |- packages
    
    So now we host two different applications with the same core files, having a much better control about the fuel distribution. This also means that when updating FUEL we must be more careful, because we affect all apps, but hey! that's why there's webmasters right? Personally I think this structure is much more useful. So If you only have one app it doesn't matter, but you could host multiple apps right from the start. I would suggest that this structure made it to the final v1.0 of FUEL. So, now what changes must we make to let this happen? Well that's the best thing of all, we must only make a small change that we would make anyways. In the index.php file inside the public folder (the 'frontend' of our app) we make this change: From:
    /**
      * Set all the paths here
      */
     $app_path  = '../fuel/app';
     $package_path = '../fuel/packages/';
     $core_path  = '../fuel/core/';
    
    To:
    /**
      * Set all the paths here
      */
     $app_path  = '../fuel/apps/my_awesome_app';
     $package_path = '../fuel/packages/';
     $core_path  = '../fuel/core/';
    
    It's just a small change that opens up a great possibility to share the framework to multiple applications. I think this should be a essential part of the framework. What do you think? One think I have to say although I'm not sure if it will work in every case is that one does not have to make the .htaccess stated in the documentation to make this work with sub-folders in the DocumentRoot (I didn't add the RewriteBase part and so on, just using the plain default .htaccess file with sub-folders in the DocRoot using this apps approach... works like a charm!). So now, on to the packages folder! Well... using this method to share the core files we can also share the packages folder, thus using only one copy of them and using them on multiple apps (which really, that's what packages are supposed to be for, isn't it?). So let me know what do you think of this!
    UPDATE 2011-04-16: Formatted the folder structures to code because it was trimming spaces.
  • Agree. It's just logic! I would be greatly stupid to simply copy all Fuel's core files again and again to make new sites (based on Fuel). And what about updating Fuel? Simple doh!
  • To be honest, this is for a large part how things are meant to work. That's why the paths in the front controller (public index.php) are configurable. The whole setup is meant to be able to have different apps work with the same packages and core. If I were to set this up myself I would do it as follows (have done similarly with CI many times already):
    - fuel
        - first_app
        - second_app
        - third_app
        - core
        - packages
    
    And then configure my front controllers to point to the same core/packages dirs but different apps. If you feel they should go into a "apps" subfolder that's up to you, and that's why we kept this configureable.
  • That's what I like the most so far with FUEL: it's really really flexible in how you can manage things. Not just about folder structure but also with classes. It's 'hard' to get the grasp right away if you come from CI because of the approach of both frameworks but once you start getting it you'll love it! BTW, for those of you that, like me, come from CI dev, here's a great start off post you SHOULD read first: http://fuelphp.com/forums/topics/view/485

Howdy, Stranger!

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

In this Discussion