Thule - 0.9.6
  • Welcome
  • Introduction
  • - MVC(Model-View-Controller)
    - Architecture of Framework
    - Flow Chart of Application
    - Services In One Server
    - Developing Guide
    - Features
  • Installation
  • Getting Started
  • - Direct Access HTTP
    - Router Access HTTP
    - Router Direct Access HTTP
    - Reserved Function
    - Convention
    - Bootstrap
    - Pack Javascript , CSS
  • Basic Modules
  • - Model
    - View
    - Controller
  • Libraries
  • - Router
    - Config
    - Response
    - Request
    - Database
    - Query
    - Cache
    - Debug
    - Log
    - Unit Test
    - Registry
    - Profile
  • Helper
  • - Auth
    - Calendar
    - Date
    - Error page
    - Email
    - Form
    - GeoIP
    - Google
    - Html Element
    - Html
    - Http
    - I18n
    - Image
    - Json
    - Jquery
    - Login
    - Layout
    - Locale
    - PHP to Javascript
    - Paging
    - Payflow
    - Soap
    - Text
    - Table
    - Uri
    - Upload
    - Validation
  • Plugins
  • - Smarty Template Engine
  • History
  • Home > Controller

    Controller is a layer of handle the business logic of site and simply gate of data stream.
    Below is sample for Controller with using the model class for database connecting and fatching data.

    Rule of class and file naming


    There is rule of filename and class name like this.

    File name : controllers/sample.php     // controllers/sample/sample.php..
    Class name : SampleController

    Create Controller Class

    When you create Controller class, you have to make the class be extended of Controller class.

    class VmController extends Controller {
    }

    Controller Sample


    Below is class sample.

    class VmController extends Controller {
           function __construct($namespace){
                  parent::__construct($namespace) ;
           }
           function f1 (){
                  $cookie['name']='THULE';
                  $cookie['value']='THULE1234';

                  $this->loadHelper("auth");
                  $c=$this->auth->get_cookie($cookie);
                  //$this->auth->del_cookie($cookie);

                  // validator
                  $this->loadHelper("validation");

                  $arr_sql['member_id']=1;

                  var_dump($this->Validation->is_numeric($arr_sql['member_id']));

                  $hconn=&$this->opendb('default');
                  $this->loadModel('sample',$hconn);
                  $this->Sample->update_member($arr_sql);
                  $result=$this->Sample->select_member($arr_sql);
                  foreach($result[0] as $var=>$value) {
                         $this->setResponse($var,$value);
                  }

                  $this->loadController("mvc","MVC");
                  $this->MVC->f1();
                  $this->view->test="test";

                  return $sql;
           }

           function f2 (){
                  var_dump($this->_request);
                  $hconn=$this->opendb('default');
                  var_dump($hconn);
                  $this->closedb($hconn);
                  return "F2";
           }
    }

    Connect database in Controller

    Simply, you can connect the database with defalut config of database(database/dbconfig) and use the models .

                  $hconn=$this->opendb('default');
                  $this->loadModel("sample",$hconn);
                  $this->Sample->update_member($arr_sql);
                  $result=$this->Sample->select_member($arr_sql);
                  foreach($result[0] as $var=>$value) {
                         $this->setResponse($var,$value);
                  }

    Load other Controllers in Controller

    Simply, you can call other Controllers and you can define the class name.
    function loadController("Controllers/directory/Controllerclass","classname",(optional for constructor) )

    $this->loadController("mvc","MVC");
    $this->MVC->f1();

    You can call the Controller with array.

    $this->loadController(array("mvc","vm",,));
    $this->Mvc->f1();
    $this->Vm->f1();

    Redirect in Controller

    $this->redirect("http://www.thuleframework.com");

    Get Request in Controller

    $this->getRequest(); // all request
    $this->getRequest('property');

    Load the Helper

    load the one helper and rename the class

    $this->loadHelper("login","Login"); // first parameter is helper class ,second is call name.
    $this->Login->islogin($hconn,$this->auth,1);

    load several helper with array at once.It is very useful when you use ther several helper in Controller and if you put them to constructor of Controller, that makes you easy way to build site.

    $this->loadHelper(array("login","json","paging",,));
    $this->Login->f1();
    $this->Json->f1();
    $this->Paging->f1();
    ......

    Load the Model

    load the one Model and rename the class

    $this->loadModel("sample",$hconn,"Sample");
    $this->Sample->sample_select($arrSql);

    load several models with array at once.It is very useful when you use ther several models in Controller and if you put them to constructor of Controller, that makes you easy way to build site.

    $this->loadModel(array("sample","sample1","sample2",,),$hconn);
    $this->Sample->f1();
    $this->Sample1->f1();
    $this->Sample2->f1();
    ......

    Reserved Function

    If you put below codes to the top of function, that fucntion should be reserved function. So just called one time.

    if($this->isReserved(__METHOD__)) return false;

    Render view or not

    This feature can allow you can determine the view will be called or not.

    render the view

    $this->render();

    no render the view

    $this->norender();

    IsPost

    This functino can check the POST you can use when you get the form value or not.

    if( $this->isPost() ) {
    // when post
    }