All controller classes for this application should extend from this base class.
Наследование: extends CController
Пример #1
1
 /**
  * Overriding parent
  *
  * @param string $name
  * @return mixed
  */
 public function __get($name)
 {
     // View
     if ($name == 'view') {
         return $this->_controllerInstance->getView();
     }
     // Request
     if ($name == 'request') {
         return $this->_controllerInstance->getRequest();
     }
     // Response
     if ($name == 'response') {
         return $this->_controllerInstance->getResponse();
     }
     // POST
     if ($name == 'post') {
         return $this->_controllerInstance->getRequest()->getPost();
     }
     // GET
     if ($name == 'query') {
         return $this->_controllerInstance->getRequest()->getQuery();
     }
     // URL parameters
     if ($name == 'params') {
         return $this->_controllerInstance->getRequest()->getParams();
     }
     // application env
     if ($name == 'appEnv') {
         return $this->_controllerInstance->getAppEnv();
     }
     parent::__get($name);
 }
 public function Select($nombre, $obs, $fecha)
 {
     $Controller = new Controller();
     $arr1 = array("NOMBRE_RETIRO_CUSTODIA", "OBSERVACION_RETIRO_CUSTODIA", "FECHA_RETIRO_CUSTODIA");
     $arr2 = array("'{$nombre}'", "'{$obs}'", "'{$fecha}'");
     return $Controller->Select2($this->_tabla, $arr1, $arr2);
 }
 /**
  * @param Controller $controller
  * @param Job $job (optional)
  */
 public function __construct($controller, $job = null)
 {
     if ($job) {
         $fields = $job->getFields();
         $required = $job->getValidator();
     } else {
         $fields = singleton('Job')->getFields();
         $required = singleton('Job')->getValidator();
     }
     $fields->merge(new FieldList(new LiteralField('Conditions', $controller->TermsAndConditionsText), new HiddenField('BackURL', '', $controller->Link('thanks')), new HiddenField('EmailFrom', '', $controller->getJobEmailFromAddress()), new HiddenField('EmailSubject', '', $controller->getJobEmailSubject()), $jobId = new HiddenField('JobID')));
     if ($job) {
         $jobId->setValue($job->ID);
         $actions = new FieldList(new FormAction('doEditJob', _t('Jobboard.EDITLISTING', 'Edit Listing')));
     } else {
         $actions = new FieldList(new FormAction('doAddJob', _t('JobBoard.CONFIRM', 'Confirm')));
     }
     parent::__construct($controller, 'AddJobForm', $fields, $actions, $required);
     $this->setFormAction('JobBoardFormProcessor/doJobForm');
     $this->setFormMethod('POST');
     if ($job) {
         $this->loadDataFrom($job);
     } else {
         $this->enableSpamProtection();
     }
 }
Пример #4
1
 public function render($action, $params = [], $cacheTime = null)
 {
     if (empty($action)) {
         return '';
     }
     $path = explode(':', $action);
     $params = ['data' => $params, 'module' => $this->controller->params['module'], 'controller' => $this->controller->params['controller']];
     switch (count($path)) {
         case 1:
             $params['action'] = $path[0];
             break;
         case 2:
             $params['controller'] = $path[0];
             $params['action'] = $path[1];
             break;
         default:
             $params['module'] = $path[0];
             $params['controller'] = $path[1];
             $params['action'] = $path[2];
     }
     try {
         if ($params['controller'] == $this->controller->params['controller'] && $params['module'] == $this->controller->params['module']) {
             return $this->controller->run($params);
         }
         return $this->controller->app->runController($params, $cacheTime);
     } catch (\Exception $e) {
         if ('dev' == $this->controller->app->conf['env']) {
             return $e;
         }
         return '';
     }
 }
 /**
  * Utility static to avoid repetition.
  * 
  * @param Controller $controller
  * @param string $identifier e.g. 'ParentID' or 'ID'
  * @retun number
  */
 public static function get_numeric_identifier($controller, $identifier = 'ID')
 {
     // Deal-to all types of incoming data
     if (!$controller->hasMethod('currentPageID')) {
         return 0;
     }
     // Use native SS logic to deal with an identifier of 'ID'
     if ($identifier == 'ID') {
         $useId = $controller->currentPageID();
         // Otherwise it's custom
     } else {
         $params = $controller->getRequest()->requestVars();
         $idFromFunc = function () use($controller, $params, $identifier) {
             if (!isset($params[$identifier])) {
                 if (!isset($controller->urlParams[$identifier])) {
                     return 0;
                 }
                 return $controller->urlParams[$identifier];
             }
             return $params[$identifier];
         };
         $useId = $idFromFunc();
     }
     // We may have a padded string e.g. "1217 ". Without first truncating, we'd return 0 and pass tests...
     $id = (int) trim($useId);
     return !empty($id) && is_numeric($id) ? $id : 0;
 }
Пример #6
1
 public function onNotFound(\Event $event)
 {
     $controller = new \Controller(\App::getInstance());
     $page = $controller->twigInit()->render(\Config::get('view::notfound_page'));
     $response = new \Response($page, 404);
     \Container::getInstance()->setResponse($response);
 }
Пример #7
0
 function errors($msg)
 {
     $controller = new Controller($this->request);
     $controller->Session = new Session();
     //  print_r($controller);
     $controller->e404($msg);
 }
Пример #8
0
 /**
  * startup
  * called after Controller::beforeFilter()
  * 
  * @param object $controller instance of controller
  * @return void
  * @access public
  */
 public function startup(Controller $controller)
 {
     // Maintenance mode OFF but on offline page -> redirect to root url
     if (!$this->isOn() && strpos($controller->here, Configure::read('Maintenance.site_offline_url')) !== false) {
         $controller->redirect(Router::url('/', true));
         return;
     }
     // Maintenance mode ON user logoout allowed
     if ($this->isOn() && strpos($controller->here, 'users/logout') !== false) {
         return;
     }
     // Maintenance mode ON but not in offline page requested - > redirect to offline page
     if ($this->isOn() && strpos($controller->here, Configure::read('Maintenance.site_offline_url')) === false) {
         // All users auto logged off if setting is true
         if (Configure::read('Maintenance.offline_destroy_session')) {
             $this->Session->destroy();
         }
         $controller->redirect(Router::url(Configure::read('Maintenance.site_offline_url'), true));
         return;
     }
     // Maintenance mode scheduled show message!!
     if ($this->hasSchedule()) {
         $this->Flash->maintenance(__('This application will be on maintenance mode at  %s ', Configure::read('Maintenance.start')));
     }
 }
 function onLaunch()
 {
     // Check the user has an appropriate role
     if ($this->user->isLearner() || $this->user->isStaff()) {
         $user_id = $this->user->getId();
         $consumer_key = $this->consumer->getKey();
         // Initialise the user session
         $model = new LTILoginer();
         $model->consumer_key = $consumer_key;
         $model->user_id = $user_id;
         // validate user and redirect if valid
         if ($model->validate() && $model->login()) {
             $returnUrl = Yii::app()->user->returnUrl;
             if (!is_null($returnUrl)) {
                 $returnUrl = array('site/index');
             }
             $this->controller->redirect($returnUrl);
         } else {
             // TODO: some error message
         }
         /*$_SESSION['consumer_key'] = $this->consumer->getKey();
           $_SESSION['resource_id'] = $this->resource_link->getId();
           $_SESSION['user_consumer_key'] = $this->user->getResourceLink()
               ->getConsumer()
               ->getKey();
           $_SESSION['user_id'] = $this->user->getId();
           $_SESSION['isStudent'] = $this->user->isLearner();
           $_SESSION['isContentItem'] = FALSE;*/
         // Redirect the user to display the list of items for the resource link
         /*$this->redirectURL = getAppUrl();*/
     } else {
         $this->reason = 'Invalid role.';
         $this->isOK = FALSE;
     }
 }
 public function beforeRender(Controller $controller)
 {
     if ($this->isBrwPanel) {
         $controller->set(array('companyName' => Configure::read('brwSettings.companyName'), 'brwHideMenu' => $controller->Session->read('brw.hideMenu')));
     }
     $this->controller->set('brwSettings', Configure::read('brwSettings'));
 }
Пример #11
0
function main()
{
    $controller = new Controller();
    $response = null;
    switch ($_POST["cmd"]) {
        case "RPC":
            $username = $_POST["user"];
            if ($username == null) {
                $username = $_SESSION['user'];
            }
            $pw = $_POST["pw"];
            $plantname = $_POST["plant"];
            $code = $_POST["code"];
            $plantid = $_POST["id"];
            $response = $controller->HandleRemoteProcedureCall($_POST["func"], $username, $pw, $plantname, $code, $plantid);
            break;
        case "ContentRequest":
            if ($controller->IsLoggedIn() != "false") {
                $response = new ContentMessage($_POST["content"], $_POST["plantid"]);
            } else {
                $func = "function() { this.showLoginDialog(); this.showMessage('Sie sind nicht eingeloggt bitte einloggen', 'error'); }";
                $response = new RemoteProcedureCall($func);
            }
            break;
        default:
            $response = new Message('error', 'unknown Command');
            break;
    }
    if ($response != null) {
        $response->send();
    } else {
        echo "Error! no response was generated";
    }
}
Пример #12
0
 public function startup(Controller $controller)
 {
     if (isset($controller->request->params['prefix']) && $controller->request->params['prefix'] == 'admin' && !$this->isLoggedIn()) {
         $this->Session->setFlash(__d('micro_auth', 'You need to login to access this page'));
         $controller->redirect($this->config['loginAction']);
     }
 }
Пример #13
0
 /**
  * Attach Recaptcha helper to Controller.
  *
  * @param Controller $controller Controller.
  *
  * @return void
  */
 public function setController($controller)
 {
     // Add the helper on the fly
     if (!in_array('Recaptcha.Recaptcha', $controller->viewBuilder()->helpers())) {
         $controller->viewBuilder()->helpers(['Recaptcha.Recaptcha'], true);
     }
 }
 public function preRequest(SS_HTTPRequest $request, Session $session, DataModel $model)
 {
     // Bootstrap session so that Session::get() accesses the right instance
     $dummyController = new Controller();
     $dummyController->setSession($session);
     $dummyController->setRequest($request);
     $dummyController->pushCurrent();
     // Block non-authenticated users from setting the stage mode
     if (!Versioned::can_choose_site_stage($request)) {
         $permissionMessage = sprintf(_t("ContentController.DRAFT_SITE_ACCESS_RESTRICTION", 'You must log in with your CMS password in order to view the draft or archived content. ' . '<a href="%s">Click here to go back to the published site.</a>'), Controller::join_links(Director::baseURL(), $request->getURL(), "?stage=Live"));
         // Force output since RequestFilter::preRequest doesn't support response overriding
         $response = Security::permissionFailure($dummyController, $permissionMessage);
         $session->inst_save();
         $dummyController->popCurrent();
         // Prevent output in testing
         if (class_exists('SapphireTest', false) && SapphireTest::is_running_test()) {
             throw new SS_HTTPResponse_Exception($response);
         }
         $response->output();
         die;
     }
     Versioned::choose_site_stage();
     $dummyController->popCurrent();
     return true;
 }
Пример #15
0
 /**
  * @param  Controller $controller
  * @param  bool       $stopPropagation
  * @return $this
  */
 public function setController(Controller $controller, $stopPropagation = false)
 {
     if (!$stopPropagation) {
         $controller->addMethod($this, true);
     }
     $this->controller = $controller;
     return $this;
 }
Пример #16
0
 public function GetMayor()
 {
     $Controller = new Controller();
     $sql = "select max(ID_MERMA) as mayor from " . $this->tabla;
     $result = $Controller->ejecute($sql);
     $row = mysql_fetch_array($result);
     return $row["mayor"];
 }
Пример #17
0
 /**
  * @access   public
  * @since    1.0.0-alpha
  * @version  1.0.0-alpha
  */
 public function handler()
 {
     header('HTTP/1.0 ' . $this->sHeaderContent);
     $oController = new Controller();
     $oView = View::factory('base/error_pages/' . $this->iHttpCode);
     echo $oController->independentResponse($oView);
     exit;
 }
Пример #18
0
    public function testRemoveBlock()
    {
        $this->controller->addBlock('CATEGORY', 'getGeneric');
        $this->setConfig('[CATEGORY]
* = remove');
        $config = $this->renderer->getBlockConfiguration('CATEGORY');
        $this->assertEquals($config[0]['action']['command'], 'remove');
    }
Пример #19
0
 function error($message)
 {
     header("HTTP/1.0 404 Not Found");
     $controller = new Controller($this->request);
     $controller->set('message', $message);
     $controller->render('/errors/404');
     die;
 }
 /**
  * Executes the main functionality of the output processor
  *
  * @param \Controller $controller The relevant SilverStripe controller
  * @param mixed $result The result from the input processor
  * @return \SS_HTTPResponse
  */
 public function process(\Controller $controller, $result = null)
 {
     $response = $controller->getResponse();
     $response->setStatusCode(200);
     $response->addHeader('Content-Type', 'application/json');
     $response->setBody(json_encode(['success' => (bool) $result]));
     return $response;
 }
Пример #21
0
 public static function findPage(Controller $oController)
 {
     if (self::$currentPageID > 0) {
         return;
     }
     if ($oController->indexPage()) {
         $oPage = new Page();
         if ($oPage->loadIndexPage()) {
             if (Controller::getInstance()->controllerExists($oPage["Link"])) {
                 $oController->route[self::$level] = $oPage["Link"];
             }
             self::$level = 1;
             self::$page = $oPage;
             self::$currentPageID = $oPage->PageID;
         }
     } else {
         $db = MySQL::getInstance();
         $db->query("SELECT PageID, StaticPath, Level, LeftKey, RightKey, Link\n\t\t\t\tFROM `page` WHERE\n\t\t\t\t\tWebsiteID = " . $db->escape(WEBSITE_ID) . "\n\t\t\t\t\tAND StaticPath IN (" . implode(", ", $db->escape($oController->route)) . ")\n\t\t\t\t\tAND LanguageCode = " . $db->escape(LANG) . "\n\t\t\t\t\tAND Level > 1\n\t\t\t\tORDER BY LeftKey");
         self::$level = 0;
         $moduleFound = false;
         $currentPageID = null;
         while ($row = $db->fetchRow()) {
             if ($row["StaticPath"] == $oController->route[0] && $row["Level"] == 2) {
                 $currentPageID = $row["PageID"];
                 self::$currentLeftKey = $row["LeftKey"];
                 self::$currentRightKey = $row["RightKey"];
                 if ($moduleFound = Controller::getInstance()->controllerExists($row["Link"])) {
                     $oController->route[0] = $row["Link"];
                     break;
                 }
                 self::$level++;
                 continue;
             }
             if (!is_null($currentPageID) && count($oController->route) > self::$level) {
                 if ($row["StaticPath"] == $oController->route[self::$level] && $row["LeftKey"] > self::$currentLeftKey && $row["RightKey"] < self::$currentRightKey) {
                     $currentPageID = $row["PageID"];
                     self::$currentLeftKey = $row["LeftKey"];
                     self::$currentRightKey = $row["RightKey"];
                     if ($moduleFound = Controller::getInstance()->controllerExists($row["Link"])) {
                         $oController->route[self::$level] = $row["Link"];
                         break;
                     }
                     self::$level++;
                 }
             }
         }
         if (self::$level == count($oController->route) || $moduleFound != false) {
             $oPage = new Page();
             if ($oPage->loadByID($currentPageID)) {
                 self::$page = $oPage;
                 self::$currentPageID = $oPage->PageID;
             }
         }
     }
     for ($i = 0; $i < self::$level; $i++) {
         array_shift($oController->route);
     }
 }
Пример #22
0
 /**
  * setUp method
  *
  * @access public
  * @return void
  */
 public function setUp()
 {
     $this->Controller = new ArticlesTestController();
     $this->Controller->constructClasses();
     $this->Controller->params = array('named' => array(), 'pass' => array(), 'url' => array());
     $this->Controller->modelClass = 'Article';
     $this->Controller->Archive = new ArchiveComponent($this->Controller->Components);
     $this->Controller->Archive->startup($this->Controller);
 }
Пример #23
0
 private function verificarAcao($ch_modulo, $ch_controller, $ch_action)
 {
     $modulo = new Modulo();
     $controller = new Controller();
     $action = new Action();
     $id_modulo = $modulo->getIdModuloByCh($ch_modulo);
     $id_controller = $controller->getIdControllerByCh($ch_controller);
     $action->verificarAcao($id_modulo, $id_controller, $ch_action);
 }
Пример #24
0
 public function __construct(View $view, Request $request, array $routes, Controller $controller = null, $model = null)
 {
     $this->view = $view;
     $this->request = $request;
     $this->controller = $controller;
     $this->model = $model;
     $this->routes = $routes;
     $this->viewLocator = $controller !== null ? $controller->getViewLocator() : null;
 }
Пример #25
0
 public function renderView($path, $vars = array())
 {
     // Create empty controller and inject services to it
     $controller = new Controller();
     $controller->setServiceContainer($this->services);
     // Create and display the response
     $response = $controller->render($path, $vars);
     echo $response->getContent() . "\n";
 }
Пример #26
0
/**
 * Returns the test controller
 *
 * @return Controller
 */
	function _getController($request, $response) {
		if ($this->testController === null) {
			$this->testController = parent::_getController($request, $response);
		}
		$this->testController->helpers = array_merge(array('InterceptContent'), $this->testController->helpers);
		$this->testController->setRequest($request);
		$this->testController->response = $this->response;
		return $this->testController;
	}
Пример #27
0
 /**
  * @return \CountryMap 
  */
 private static function populateCountryMap()
 {
     $dao = new GenericDao(Connection::connect());
     $controller = new Controller($dao);
     $countryMap = new CountryMap();
     $countryMap->addOrigins($controller->listOrigins());
     $countryMap->addDestinies($controller->listDestinies());
     return $countryMap;
 }
Пример #28
0
 public function testInvalidState()
 {
     $controller = new Controller();
     $request = new Request(['code' => 'foo', 'state' => 'foo']);
     $response = new Response();
     $response = $controller->redirect($request, $response);
     $html = $response->getContent();
     $this->assertContains('Invalid State', $html);
 }
 /**
  * Edited version of the GridFieldEditForm function
  * adds the 'Bulk Upload' at the end of the crums
  * 
  * CMS-specific functionality: Passes through navigation breadcrumbs
  * to the template, and includes the currently edited record (if any).
  * see {@link LeftAndMain->Breadcrumbs()} for details.
  * 
  * @author SilverStripe original Breadcrumbs() method
  * @see GridFieldDetailForm_ItemRequest
  * @param boolean $unlinked
  * @return ArrayData
  */
 public function Breadcrumbs($unlinked = false)
 {
     if (!$this->controller->hasMethod('Breadcrumbs')) {
         return;
     }
     $items = $this->controller->Breadcrumbs($unlinked);
     $items->push(new ArrayData(array('Title' => 'Bulk Editing', 'Link' => false)));
     return $items;
 }
Пример #30
0
 /**
  * action的构造函数
  * 
  * @access public
  * @param Controller $controller  控制器 
  * @param String $id Action ID
  */
 public function __construct($controller, $id)
 {
     $this->controller = $controller;
     if (isset($controller->layout)) {
         $controller->setLayout($controller->layout);
     }
     $this->setData($controller->datas);
     $this->id = $id;
 }