- Seme Framework
- version 4.0.3
- Requirements
- Download & Install
- Configuration
- Tutorials
- URI Routing
- Constants
- Global Variables
- Model
- View
- Controller
- cdn_url
- config
- constructor
- getAdditional
- getAdditionalBefore
- getAdditionalAfter
- getAuthor
- getCanonical
- getContentLanguage
- getDescription
- getIcon
- getJsContent
- getJsFooter
- getJsReady
- getKey
- getKeyword
- getLang
- getRobots
- getShortcutIcon
- getThemeElement
- getTitle
- input
- lib
- load
- loadCss
- loadLayout
- putThemeContent
- putJsContent
- putJsFooter
- putJsReady
- putThemeContent
- render
- resetThemeContent
- session
- setAuthor
- setCanonical
- setContentLanguage
- setDescription
- setIcon
- setKey
- setKeyword
- setLang
- setShortcutIcon
- setTheme
- setTitle
- Library
- CLI (command line interface)
- Core
- Issue
- Deployment
Core Controller
Core Controller class is the feature of Seme Framework that allowed SENE_Controller to be extended or customized like add some methods or some properties.
When do I use this?
Use this feature when you need globally available methods for each class, e.g. controller class.
Enable the Core Controller
For enabling the core class, simply edit the Seme Framework Configuration files and then put the class controller file inside app/core
.
Editing the Configuration
Lets say, the prefix of core class is ji_
and then the core controller class is controller
.
...
/********************************/
/* == Core Configuration == */
/* register your core class, and put it on: */
/* - app/core/ */
/* all var $core_* value in lower case string*/
/* @var string */
/****************************/
$core_prefix = 'ji_';
$core_controller = 'controller';
$core_model = '';
...
The JI_Controller.php
file
On this example, we will add __json_out
method to JI_Controller
class.
Do not forget to add __construct
method and index
method, because they are required from SENE_Controller abstract class.
Save the file under app/core/ji_controller.php
.
<?php
/**
* Main controller: contains about methods and protperties that automtically included after extending in a class
*/
class JI_Controller extends SENE_Controller
{
// required function for triggering parent class
public function __construct()
{
parent::__construct();
}
/**
* Output the json formatted string
* @param mixed $dt input object or array
* @return string sting json formatted with its header
*/
public function __json_out($dt)
{
$this->lib('sene_json_engine', 'sene_json');
$data = array();
if (isset($_SERVER['SEME_MEMORY_VERBOSE'])) {
$data["memory"] = round(memory_get_usage()/1024/1024, 5)." MBytes";
}
$data["status"] = (int) $this->status;
$data["message"] = $this->message;
$data["data"] = $dt;
$this->sene_json->out($data);
die();
}
//required function from abstract class
public function index(){ }
}
How to use
While creating controller class, extends the controller class from JI_Controller
class, not with SENE_Controller class.
<?php
class Apikey extends JI_Controller {
public function __construct(){
parent::__construct();
$this->load("api_mobile/a_apikey_model","aakm");
}
public function index(){
$this->status = 200;
$this->message = 'Success';
$data = array();
$this->__json_out($data);
}
}