Question

At this moment i am having a problem, my controller called userspace, his model called userspace and view is userspace too, logically everything is fine, but just a plain example when you open this 3 files sometimes it's hard to understand where is model and where is controller if not to start reading the code. So i ask for advises or examples of coding standarts :)

Was it helpful?

Solution

I normally tend to use singular/plural to distinguish from model/controller. That being said, this is how I do things:

Model

  • File name: app/classes/model/userspace.php
  • Class name: Model_Userspace

This is also FuelPHP's naming convention (at least for Models). This way you don't have to specify the table name on the model, like so:

protected static $_table_name = 'userspaces';

because FuelPHP will look for the plural version of your model name.

Controller

  • File name: app/classes/controller/userspaces.php
  • Class name: Controller_Userspaces

Views

  • Folder: app/views/userspaces/

This keeps things organized per controller name. For each controller action, a view should be created. So, if you have a create and edit action in your Controller_Userspaces, you will create the following files:

  • Create: app/views/userspaces/create.php
  • Edit: app/views/userspaces/edit.php

Forging the views should be a matter of calling:

View::forge('userspaces/create');
View::forge('userspaces/edit');

You should check the FuelPHP ORM documentation for more information.

OTHER TIPS

UserSpaceView(view/gui) / UseSpaceViewController(controller) / UserSpaceModel(model)

We namespace everything, instead of using underscores, so

\Controller\Userspace
\Model\Userspace
\View\Userspace

and

\Module\Controller\Userspace
\Module\Model\Userspace
\Module\View\Userspace

For models you can do directly, for controllers you need to change the controller prefix in the config (from "Controller_" to "Controller\"), which means you have to namespace ALL your controllers from this point.

This is going to be the standard for Fuel v2, it will not support "underscore to directory separator" mapping anymore.

Note that \View maps to ./classes/view, which are Viewmodel classes, not View files!

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