/**
  * Execute action
  *
  * @param string $action
  * @return null
  */
 function execute($action)
 {
     parent::execute($action);
     if ($this->getAutoRender()) {
         $render = $this->render();
     }
     // Auto render?
     return true;
 }
 /**
  * @desc Cleans the output buffer and execute the given controller before exiting
  * @param Controller $controller the controller to execute
  */
 public static function redirect(Controller $controller)
 {
     AppContext::get_response()->clean_output();
     Environment::init_output_bufferization();
     $request = AppContext::get_request();
     $response = $controller->execute($request);
     $response->send();
     Environment::destroy();
     exit;
 }
 /**
  * Execute action
  *
  * @param string $action
  * @return null
  */
 function execute($action)
 {
     if ($this->request->isApiCall() && !in_array($this->request->getAction(), $this->api_actions)) {
         $this->httpError(HTTP_ERR_FORBIDDEN, null, true, true);
     }
     // if
     $execute = parent::execute($action);
     if (is_error($execute)) {
         return $execute;
     }
     // if
     if ($this->getAutoRender()) {
         $render = $this->render();
         if (is_error($render)) {
             return $render;
         }
         // if
     }
     // if
     return true;
 }
Example #4
0
<?php

/* Let's do something MVC-ish 
   (purists might disagree that this is MVC)*/

require_once( 'model.php' );
require_once( 'view.php' );
require_once( 'controller.php' );

$model = new Model();
$view = new View();
$controller = new Controller();

$view->model = $model;
$controller->model = $model;
$controller->view = $view;

$controller->execute();

?>
include_once "include/Dashboard.php";
$ctrl = new Controller();
$ctrl->PreLoad($roles);
define("LOGINTYPE", $ctrl->usertype);
define("USERID", $ctrl->userid);
define("LEVEL", $ctrl->level);
//print($ctrl->usertype);print(USERID);
require_once "module/admin.php";
foreach ($roles[$ctrl->usertype] as $key => $val) {
    foreach ($val as $k => $v) {
        if ($v == 1) {
            $module_setting[$key][$k] = $config[$key][$k];
        }
    }
}
//print_r($module_setting);
$ctrl->Module($obj);
$ctrl->LoadModule();
$ctrl->ModuleSetting("filter", $filter);
$ctrl->ModuleSetting("table", $table);
$ctrl->ModuleSetting("key", $key1);
$ctrl->ModuleSetting("basetpl", $basetpl);
$ctrl->ModuleSetting("datafield", $datafield);
$ctrl->ModuleSetting("field", $field);
$ctrl->ModuleSetting("header", $header);
$ctrl->setting = $module_setting[$ctrl->module];
$ctrl->roles = $roles;
//  Prepare and execute function detached from cases
if ($ctrl->prepare()) {
    $ctrl->execute();
}
Example #6
0
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 * Description of Variable
 *
 * @author pei
 */
include_once './ViewHelper.php';
class Controller
{
    //put your code here
    public function execute()
    {
        $viewhelper = new ViewHelper();
        $test = "H";
        $hej = "då";
        $viewhelper->assign('marke', 'Volvo');
        $viewhelper->assign('modell', 'XC90');
        $viewhelper->assign('pris', 235000);
        $viewhelper->assign('rabatteratPris', 235000 * 0.9);
        $viewhelper->assign('datum', date("Y-h-d"));
        $viewhelper->assign('bild', 'http://www.largus.fr/images/images/Volvo-XC-90-2014_1.jpg');
        $viewhelper->display('./Variables.html');
    }
}
$cont = new Controller();
$cont->execute();
Example #7
0
 function executeAction($controller, $params)
 {
     // Where to find what
     $this->paths = array(BASEAPP_PATH, APP_PATH);
     $controller_class = Inflector::camelize($controller);
     $controller_class_name = $controller_class . 'Controller';
     // Is it a component
     if (is_dir(APP_PATH . 'components/' . $controller)) {
         $this->paths[] = APP_PATH . 'components/' . $controller . '/';
     }
     uses($controller_class, B_CONTROLLER);
     // get a instance of that controller
     if (class_exists($controller_class_name)) {
         $this->Controller = new $controller_class_name();
     } else {
         //page_not_found();
     }
     if (!is_subclass_of($this->Controller, 'Controller')) {
         die("Class '{$controller_class_name}' does not extends Controller class!");
     }
     // Setup database is required
     if (Configure::read('dbName')) {
         // connect to db
         include CORE_PATH . 'libraries/adodb/adodb.inc.php';
         extract(Configure::readConfig());
         $this->Controller->db = ADONewConnection($dbType);
         # eg 'mysql' or 'postgres'
         if (!$this->Controller->db->Connect($dbHostname, $dbUsername, $dbPassword, $dbName)) {
             throw new Exception('Could not connect to database');
         }
     }
     // Various controller globals
     $this->Controller->base = getInstance();
     $this->Controller->Session = new Session();
     $this->Controller->Cookie = new Cookie();
     $this->Controller->data = $this->Controller->getData();
     // load the helpers,libraries and models
     if (isset($this->Controller->helpers)) {
         uses($this->Controller->helpers, B_HELPER);
     }
     if (isset($this->Controller->libraries)) {
         uses($this->Controller->libraries, B_LIBRARY);
     }
     if (isset($this->Controller->uses)) {
         uses($this->Controller->uses, B_MODEL);
     }
     //beforeFilter
     if (method_exists($this->Controller, 'beforeFilter')) {
         call_user_func(array($this->Controller, 'beforeFilter'));
     }
     // load the helpers,libraries and models if any changes made by before filter
     if (isset($this->Controller->helpers)) {
         uses($this->Controller->helpers, B_HELPER);
     }
     if (isset($this->Controller->libraries)) {
         uses($this->Controller->libraries, B_LIBRARY);
     }
     if (isset($this->Controller->uses)) {
         uses($this->Controller->uses, B_MODEL);
     }
     $this->Controller->execute($this->actionName, $this->params);
 }
<?php
require('boot.php');

$c = new Controller;
$c->execute();

class Controller {
  var $renderer;
  var $fb;
  var $session;
  var $auth_url;
  var $user;

  function __construct(){
    // create renderer
    $this->renderer = new Mustache;

    // create fb api
    $this->fb = new Facebook(array(
      'appId' => FB_APP_ID,
      'secret' => FB_SECRET, 
      'cookie' => true,
    ));   
    // get session
    $this->session = $this->fb->getSession();
  }

  function execute() {
    $this->return_search_results();

    // front controller 
 private function integrated_display(Controller $controller)
 {
     $request = AppContext::get_request();
     $response = $controller->execute($request);
     $response->send();
 }
Example #10
0
 public static function run($fromRequest, $path = null, $method = null, $get = array(), $post = array(), $cookies = array(), $headers = array(), $body = null, &$status = null)
 {
     $c = new Controller($fromRequest, $path, $method, $get, $post, $cookies, $headers, $body);
     $result = $c->execute();
     $status = $c->status;
     return $result;
 }
Example #11
0
 /**
  * The main execution method for the Saffyre framework. The method should only be invoked ONCE and there is no guarantee that
  * it will return execution (many methods and controllers will die or exit). This method starts an output buffer.
  *
  * @param string $path The path to execute, or the request URI if null
  * @param boolean $return True to return the response, or false to flush it.
  * @uses Controller
  */
 public static function execute($path = null, $return = false)
 {
     ob_start();
     if (!$path) {
         $path = strtok($_SERVER['REQUEST_URI'], '?');
     }
     self::$path = self::cleanPath($path);
     $required = array("URL_BASE", "URL_PATH");
     $undefined = array();
     foreach ($required as $const) {
         if (!defined($const)) {
             $undefined[] = $const;
         }
     }
     if ($undefined) {
         throw new Exception('The following constants are not defined: ' . join(', ', $undefined));
     }
     if (!defined('ENCODING')) {
         define('ENCODING', 'UTF-8');
     }
     header('Content-type: text/html; charset=' . ENCODING);
     header("X-Powered-By: Saffyre Framework 2.0", true);
     //include_once dirname(__FILE__) . '/Controller.php';
     $controller = new Controller(true, self::$path);
     $controller->isMainRequest = true;
     $response = $controller->execute(true);
     if (!$controller->resultWasOutput) {
         if (array_filter(headers_list(), function ($c) {
             return strpos(strtolower($c), 'content-type: application/json') === 0;
         })) {
             if ($response instanceof JsonSeriazable) {
                 echo json_encode($response);
             } else {
                 if (method_exists($response, '__toJson')) {
                     echo $response->__toJson();
                 } else {
                     echo json_encode($response);
                 }
             }
         } else {
             echo $response;
         }
     }
     if ($controller->status != null) {
         Saffyre::responseStatus($controller->status);
     }
     if ($return) {
         return ob_get_clean();
     } else {
         ob_flush();
     }
 }