- 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
Controller Class
Controller is a class that inherited from SENE_Controller and its derivatives*. Also, controller has another requirements before it can used by Seme Framework.
Before going further, we have to find out the condition for Seme Framework to meet its controller requirements.
Requirements
The following are the conditions when you want to use the Controller class correctly so that it can run properly:
Location
All Controller classes are stored in the app/controller
directory.
Class Inheritance
The controller class must be extends
from SENE_Controller .
But, If using * core controller
as parent class, the core controller class must be extends
from SENE_Controller .
Naming Rules
The naming of the controller file name and controller class name can only be started by a letter, then followed by letters and or numbers, and/or an underscore. The class name and file name must be identical but may not be uppercase or lowercase (not case sensitive)
Filename Extension
The controller class file name must be in lower case and the filename suffix is .php
.
Defaults
The default name of class controller is Home
.
And then, the default method name of class controller is index
.
This default will be used as fallback if URI Request was empty.
How It Work
Seme Framework will be loaded a controller by URI request. Typically there is a one-to-one relationship between an URL string and its corresponding controller class/method. The segments in an URI normally follow this pattern:
example.com/class/method/parameter1/parameter2/.../parameterN
Or if using directory:
example.com/directory/class/method/parameter1/parameter2/.../parameterN
Seme Framework will only load controller with filename and its class name are matched. But, Seme Framework has support for URI Controller Remapping.
The Notfound
Error 404 or Notfound is a special controller which serves as fallback if the controller has notfound while the controller requirements is not met.
Error 5xx
The error 500 or another 5xx codes, ussualy caused by mismatched class name with filename. However, this condition can also be caused by an error on source code.
Code Example
Lets say, you have extracted Seme Framework on D:\XAMPP\htdocs\seme_framework
So, if you accessing the http://localhost/seme_framework
the Seme Framework will load home.php
controller inside app/controller
.
Here is the basic example for a controller structure.
app/
└── controller/
├── blog.php
└── product/
├── home.php
└── detail.php
Inside controller directory, can contain a directory (folder) or file. But, the directory tree level only support 2 level. So, be wise using the directory structure.
Another Example
How if we accessing http://localhost/seme_framework/blog
?
The answer is, Seme Framework will load controller blog.php as long as the controller requirements is fulfilled.
SENE_Controller
The SENE_Controller class is basic class for creating controller which contain properties and methods that are required for using Seme Framework properly.
Basic Usage
Here is some basic usage for creating controller
Default Controller
Here is the default source code of controller.
<?php
class Home extends SENE_Controller{
public function __construct(){
parent::__construct();
}
public function index(){
echo 'Thankyou for using Seme Framewrok';
}
}
Notfound Controller
Here is the default source code for notfound controller.
<?php
class Notfound extends SENE_Controller{
public function __construct(){
parent::__construct();
}
public function index(){
header("HTTP/1.0 404 Not Found");
echo '404 Notfound';
}
}
Access Methods
Seme Framework supported access method for public and private declaration.
Private Properties and Methods
Seme Framework allow your method in Private or in Protected mode. The Private or Protected mode cant be executed through URI request. Or you can use double underscore (__) means as Private properties or methods.
class Home extends SENE_Controller{
var $public_var = 'Yi-Ha!';
var $__underWear = 'My Private Things';
public function __construct(){
parent::__construct();
}
private function __processFile(){
return true;
}
public function index(){
echo '404 Notfound';
}
}
SENE_Controller Class Diagram
Here is the technical specification of SENE_Controller class ilustrated by a class diagram.