gnuherds-app-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

MVC Branch


From: Klaus Weiss
Subject: MVC Branch
Date: Mon, 09 Apr 2007 16:12:44 +0200

I have now almost all fundamental stuff for a new
branch implemented. Since code can explain much more
than plain words here is a simple controller:

<?php
class IndexController extends Controller
{
  public $name = 'Index';
  public $model = array('User', 'Test');
  public default_action = 'view';

  public function view()
  {
    /* Do something interesting. */
  }
}
?>

Thats it! With $name you make clear which controller
you are going to use - this isn't really necessary,
however it is always more secure to set it.

$mode is an array which describes which Models you 
want to use. I describe models later.

$default_action is the default function which will
be called if the user (URL) don't give any information
about this.

Within each function there are several builtin methods
for various purposes (e.g. Database, Template, User
Management etc.).

I haven't implemented all possible methods, however
there are currently enough to do some queries.

One of this methods are the set/get ones. You
can for example do this:

$this->model['User']->setName('Klaus') 

which will set the column Name of the User Model to
'Klaus'. 

$this->model['User']->getName();

will return the Name of the User Model.

set/get allows also optional parameters for an
additional WHERE condition or a other Model name.
(This is currently the only way to set/get a specific row, 
I want to implement better solutions).


Model; with the model class you actually describe a
specific table (e.g. User). Again here is a bunch
of lines:

<?php
class User extends Model
{
  public $name = 'User';
  
  public $validate = array('id' => VALID_NUMBER);
}
?>

Again the `public $name` line is optional.

With $validate you can build an array which describes
your table more exact. There are several constants
(e.g. VALID_NUMBER, VALID_EMAIL, VALID_NOT_EMPTY) for
this job. Now if you want to save data our Model
checks first if there was something specified with
$validate. If a column fails this tests our Model
will trigger an error function - which we can
controll with our View class.

Our View class itself is nothing special. It just
integrates Smarty as the engine behind it and will
have nearly only wrapper functions.

I also integrated mod_rewrite for cleaner URL's.

Any suggestions? There is of course still a lot
of work! You can compare this script with cakephp.org,
however a lots of things are different (purged)
as I wanted to develop a much simpler and smaller
script.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]