Skip to content
henrikhofmeister edited this page Nov 1, 2010 · 1 revision

The Pimple MVC structure is fairly straight forward.

Controllers

Quick Facts:

  • Controller classes must extend Controller
  • Controller class names must end on "Controller" - E.g. HelloworldController
  • Controller class must either be pre-included (in bootstrap file) or placed in the /controller/ folder of your project in a file named after the contained controller (e.g. HelloworldController.php)
  • Controller class names cannot contain camelcasing - it should start with an uppercase latter - be all lower-case from then on - and end on "Controller" with an upper-case C. The reason for this is to allow lowercase urls (the framework cannot guess which camelcasing you are using...)
  • You have a couple of methods to help you do some common tasks inherited from the Controller class, including sending data to the view, outputting json, json or similar, setting controller scoped session variables, validating input, redirecting and more. For a complete reference click here

Urls are parsed by the Pimple class  when calling Pimple::instance()->run(); and are interpreted as /<ControllerClass>/<methodName>/. There are currently no way of rewriting and / or extending this - but could be done somewhat easily (handled in Pimple::execute)

Model The model / domain object implementation is currently very basic. You extend Model and define the table fields and other properties within the constructor. I've attempted to copy a bit of jQuery set / get logic in that each column can be gotten by calling $row->ColumnName() and updated by calling $row->ColumnName("somevalue");. The main point to this is accessing properties on a null object in PHP is supported and thus can confuse a great deal. Calling a method on a null object causes fatal error.... The "best-practice" way of implementing domain objects is to allow your constructors to take 1 optional parameter - namely the $data parameter from the Model::__construct(). Read more

View

The view is basically a HTML file - with custom taglibs mixed in. This is a bit more complex than a couple of lines so click here to view the taglib specs

Clone this wiki locally