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.

Class home on (app/controller/home.php) file is the default access controller from each URI even in the sub directory.

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';
  }
}

Caution

There is necessary to add header information on notfound class, because Seme Framework do not provided Error 404 automatically.

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';
  }
}

The private method or private properties on Seme Framework are always prefixed with double underscore.

The private method is inaccessible from URI request.

SENE_Controller Class Diagram

Here is the technical specification of SENE_Controller class ilustrated by a class diagram.

<<abstract>> SENE_Controller
+# $config: object
+# $input: SENE_Input
+ __construct(): void
+# cdn_url(): string
+# getAdditional(): void
+# getAdditionalBefore():
+# getAdditionalAfter():
+# getAuthor(): string
+# getCanonical(): string
+# getContentLanguage(): string
+# getDescription(): string
+# getIcon(): string
+# getJsContent(): void
+# getJsFooter():
+# getJsReady():
+# getKey(): mixed
+# getKeyword(): string
+# getLang(): string
+# getRobots(): string
+# getShortcutIcon(): string
+# getThemeElement():
+# getTitle():
+# lib():
+# load():
+# loadCss(): $this
+# loadLayout(): $this
+# putThemeContent(): $this
+# putJsContent(): $this
+# putJsFooter(): $this
+# putJsReady(): $this
+# putThemeContent(): $this
+# render(): void
+# resetThemeContent(): $this
+# $session
+# setAuthor(): $this
+# setCanonical(): $this
+# setContentLanguage(): $this
+# setDescription(): $this
+# setIcon(): $this
+# setKey(): $this
+# setKeyword(): $this
+# setLang(): $this
+# setShortcutIcon(): $this
+# setTheme(): $this
+# setTitle(): $this
+# index(): void