- Remember - all classes start with
_
(our fake namespace) - Basic object "Nimbus" class is
_
(in/_/lib/o/o.php
) - Models are subclasses of
_Model
- Presenters are subclasses of
_Presenter
- Views are static HTML, but typically have template segments (e.g.,
$template['main']
or$template['err']
)
/-
-> fake API requrests
/-/vacations.php
->http://site.com/-/vacations
/_
-> “app” directory
/_/_.php
- bootstrap file
- everything happens here
/_/lib
- library files
/_/lib/inc
- includes
/_/lib/array.php
- array files
$ary = array();
$ary[‘user’][‘name’][‘first’] = ‘john’;
$ary[‘user’][‘name’][‘last’] = ‘chen’;
$ary = array_collapse($ary[‘user’]);
// $ary[‘user’][‘name-first’] = ‘john’;
// $ary[‘user’]['name-last’] = ‘chen’;
$user = array();
$user[‘name-first’] = ‘john’;
$user['name-last’] = ‘chen’;
$user = array_expand($user);
// $user[‘name’][‘first’] = ‘john’;
// $user[‘name’][‘last’] = ‘chen’;
$user = new _User($user);
$user->save();
$user->name[‘first’] = ‘john’;
$user->save();
$array = array(
‘animals’ => array(
‘cats’ => array(),
‘dogs’ => array()
)
);
$element = array_pick($array, array(‘animals’,’cats’));
// basically equivalent to $element[‘animals’][‘cats’]
/_/inc/sys.php
- system stuff, low-level
/_/lib/o
- objects
/_/lib/o/o.php
- master class (class_
) - everything is a subclass of this/_/lib/o/router.o.php
- router/_/lib/o/api.o.php
- basic api class (new api for each project)/_/lib/o/sfm.api.o.php
- SFM project-specific functions
/_/lib/m
- models
/_/lib/m/m.php
- basic model (also subclass of_
)
$model = new _Model(array(
FETCH_FROM_DB => true,
‘id’ => 11
));
// will return new _Model with id 11 from table “models”
/_/lib/m/page.m.php
- page model
/_/lib/m/user.m.php
- user model
- You should be able to specify any db field to query against (in this case,
email
), but you’ll only get the first result if there’s more than one. Try to stick toid
oruuid
/_/lib/m/vacations.m.php
- vacations model
- URL:
//site.com/vactions
$vacation = new _Vacation(array(
FETCH_FROM_DB => true,
‘uuid’ =>‘mXFKtXqDNc8hwDsR7JeyG8JfkaR7’
));
// will return new _Vacation with data from given ‘uuid’ field in table ‘vacations’
- You can specify
id
,uuid
, orslug
to get records from DB - noteslug
may not be unique, so don’t rely on that; uuid is preferred
/_/lib/m/admin.m.php
- admin widget model
$this->obj
-> current object- Functions correspond to
$url->pieces[2]
(‘add’,’edit’,’submit’) - URL:
//sfm.dev/admin/{model}/{action}/{args}
- URL:
//sfm.dev/admin/{model}/{action}?id={id}&stuff={stuff}
Sometimes add
method is not specified, because it does edit
with no args
/_/lib/m/vacations.admin.m.php
- vacations admin widget model
/_/lib/p
- presenters
/_/lib/v
- views
One of the most central pieces of this framework is the use of the superglobal array, $_
. You must declare global $_;
at the top of any function to access $_
Some references - most are defined in /_/_.php
:
$_['.']
= full path of_
directory (not doc root)$_['/']
= array of directories$_['db']
= DB object / controller$_['db']->get(‘users’);
= DB query ->select * from users
- More stuff in
/_/o/db.o.php
- More stuff in
$_['user']
=$_['usr']
= current user$_['page']
= current page$_['site']
= current site