Last active
September 25, 2015 22:48
-
-
Save damiencorpataux/997761 to your computer and use it in GitHub Desktop.
xfreemwork examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
route.0.pattern = api/:xcontroller/:xaction/:id | |
route.0.xfront = api | |
route.1.pattern = :xcontroller/:xaction/:id | |
route.1.xfront = web |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class PageModel extends xModelMysql { | |
var $mapping = array( | |
'id' => 'id', | |
'title' => 'title', | |
'body' => 'body', | |
'category_id' => 'fk_category__id' | |
); | |
var $joins = array( | |
'category' => 'LEFT JOIN category ON category.id = page.category_id' | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class PagesController extends xWebController { | |
// WebFront can only call ...Action() controller methods | |
function defaultAction() { | |
// Retrives page from database | |
// if id param is missing, the 404 not found exception | |
// is converted to a 404 page by the WebFront | |
$page = xModel::load( | |
'page', | |
array('id' = @$this->params['id']) | |
)->get(); | |
// Sets page title, etc | |
// using the meta-information system of the framework | |
$this->add_meta('title', $page['title']); | |
$this->add_meta('keywords', $page['title']); | |
// Returns contents to WebFront decorator | |
// it could be any existing decorator (called Front) | |
return xView::load('page/detail', $page); | |
} | |
// RestFront and ApiFront can call public controller methods | |
// the function call result is translated to json by the Fronts | |
function get() { | |
// Role check | |
if (!xContext::$auth->is_role('viewer')) throw new xException('...', 403); | |
// Format result for extjs, | |
// the RestFront will handle the json encoding | |
return array( | |
'success' => true, | |
'count' => xModel::load('page', $this->params)->count(), | |
'data' => xModel::load('page', $this->params)->get() | |
) | |
} | |
function put() { | |
// Role check | |
if (!xContext::$auth->is_role('writer')) throw new xException('...', 403); | |
// Format result for extjs, | |
// the RestFront will handle the json encoding | |
return array( | |
'success' => true, | |
'data' => xModel::load('page', $this->params)->put() | |
) | |
} | |
function post() { | |
// Role check | |
if (!xContext::$auth->is_role('writer', 'reviewer')) throw new xException('...', 403); | |
// Format result for extjs, | |
// the RestFront will handle the json encoding | |
return array( | |
'success' => true, | |
'data' => xModel::load('page', $this->params)->post() | |
) | |
} | |
// Protected method | |
protected function createTags() { } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment