Question

This question is in regard to F3 (Php Fat Free framework) onto which I have stumbled looking for a simple, fast and secure framework suitable for small websites and/or blogs. What was important to me was that the framework have some sort of ACL, and simplicity. If you know of any good alternatives, I'm all ears. In the meantime, a question about F3 for those who have had experience with it:

Is it possible to have a decent OOP MVC structure with F3? Since routes like F3::route('GET /',':indexController|home'); do not work, how would one implement a proper MVC structure? I know I can set the home method to static and then do F3::route('GET /','indexController::home');, but this seems like unnecessary complication and overkill, and ignores the construct method, which I need to set layout for each controller separately. What I would like to have in my index.php file are only the routes to the various controllers and actions, the rest of the logic will be handled in these controllers. What is the best way to approach this?

Many thanks

Edit: I would also like to hear some opinion on Yii, I see it ranked quite highly on PHPFrameworks.com

Was it helpful?

Solution

try f3::route('GET /',array(new IndexController,'home'));

that's going to call your constructor and execute the home() method as well. f3 does not promote any "proper" MVC approach. instead, you have a "freehand" MVC approach.

OTHER TIPS

F3 doesn't bloat itself with any built in MVC architecture, it's basically just a front-controller. And that's the whole point. Instead of forcing you to use a specific set of tools, you can implement whatever you want. For example, if you don't like F3's Axon and Template plugins, you can use Red Bean ORM to manage your models, and Smarty to build your views. F3, at it's core, just routes urls to your controllers and stays out of your way.

If you want MVC, why use F3. Better use CodeIgniter or Kohana (if you got PHP 5). These are pretty lightweight too, and are built for MVC structure.

Sounds like a trip to the Bakery would not hurt. CakePHP has an excellent ACL core and can be as lightweight as you want it to be IMHO.

You can also move your routes definition to some separated config file with this example structure (routes.ini):

[routes]
GET|POST / = IndexController->indexAction
GET|POST @Index: /@lang = IndexController->langAction

and include it to F3 config:

\F3::config('routes.ini');

Next add directory with Controllers and Models in to AUTOLOADER. As a View you can use - for example PHPTal. You have now almost ready MVC over F3.

I've created a project that I call Grump-Free-Framework which does just this.

You can check out the project on github.

It uses simple map routing to call controllers in a fully modular structure, each module has it's own MVC.

/@module = modules\@module\Controller

Where you can create new modules inside the app/modules/ folder which contain a controller, optionally as many models as you want, and as many views as you want.

There is also another project which is just some basic modules, like a login module, which you can find in the readme of the grump-free-framework project.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top