getParam() public static method

Gets URL parameter by name
public static getParam ( string $name = 'controller', boolean $current = false ) : string | null
$name string Parameter name
$current boolean Current parameter, useful when using requestAction
return string | null Parameter value
 public function afterFind($results, $primary = false)
 {
     if (!in_array(Router::getParam('action'), ['editar'])) {
         $results = $this->formatDateFields($results, $this->datesToLoad, "%d/%m/%Y %H:%M");
     }
     return $results;
 }
 public function afterFind($results, $primary = false)
 {
     parent::afterFind($results, $primary);
     if (Router::getParam('action') !== 'editar') {
         return $this->formatDateFields($results, $this->datesToLoad, "%a - %d/%m/%Y %H:%M");
     }
 }
Example #3
0
 /**
  * Adiciona sempre a condição excluído = false para todas as consultas
  * (non-PHPdoc)
  * @see Model::beforeFind()
  */
 public function beforeFind($queryData)
 {
     if (Router::getParam('controller') != 'autenticacao' && $this->name != "Conta" && $this->name != "Pessoa") {
         $queryData["conditions"][$this->name . ".conta_id = "] = CakeSession::read("Auth.Indicadores.Conta.id");
     }
     $queryData["conditions"][$this->name . ".status != "] = 0;
     return $queryData;
 }
Example #4
0
 public final function checkAuthorization($user)
 {
     $controller = Inflector::camelize(Router::getParam());
     if (is_callable(array($this, 'check' . $controller . 'Authorization'))) {
         return $this->{'check' . $controller . 'Authorization'}($user);
     } else {
         return false;
     }
 }
Example #5
0
File: User.php Project: hurad/hurad
 /**
  * Called during validation operations, before validation. Please note that custom
  * validation rules can be defined in $validate.
  *
  * @param array $options Options passed from Model::save().
  *
  * @return boolean True if validate operation should continue, false to abort
  * @see Model::save()
  */
 public function beforeValidate($options = [])
 {
     parent::beforeValidate($options);
     if (Router::getParam('action') == 'admin_profile') {
         if ($this->data['User']['password'] == "" && $this->data['User']['confirm_password'] == "") {
             unset($this->data['User']['password']);
             unset($this->data['User']['confirm_password']);
         }
     }
 }
Example #6
0
 function beforeSave($data)
 {
     /* caso a ação seja adicionar, aplica a criptografia a senha */
     if (Router::getParam('action') == 'adicionar') {
         if (!empty($this->data['Usuario']['senha'])) {
             $this->data['Usuario']['senha'] = AuthComponent::password($this->data['Usuario']['senha']);
         }
     }
     return true;
 }
Example #7
0
 /**
  * [getListAccountOfCurrentUser description]
  * @return [type] [description]
  */
 public function getListAccountOfCurrentUser()
 {
     $prefix = Router::getParam('prefix', true);
     if ($prefix === 'advisor') {
         $conditions = array('BankAccount.advisor_id' => AuthComponent::user('id'));
     } else {
         $conditions = array('BankAccount.user_id' => AuthComponent::user('id'));
     }
     return $this->find('all', array('recursive' => -1, 'conditions' => $conditions));
 }
 public function beforeFilter()
 {
     parent::beforeFilter();
     if (Router::getParam('prefix', true) == 'api') {
         $this->Auth->allow('api_getTweets');
     }
     if ($this->Auth->user() != NULL) {
         $this->Auth->allow();
         $this->layout = "default_admin";
     }
 }
Example #9
0
 public function __construct($request = null, $response = null)
 {
     $page_title = Router::getParam('plugin');
     if (empty($page_title)) {
         $page_title = Router::getParam('controller');
     }
     $this->set('page_title', __(Inflector::humanize($page_title)));
     $this->set('meta_title', Configure::read('App.default_meta_title_prefix') . __(Inflector::humanize(Router::getParam('controller'))) . Configure::read('App.default_meta_title_surfix'));
     $this->set('meta_keywords', Configure::read('App.default_meta_keywords'));
     $this->set('meta_description', Configure::read('App.default_meta_description'));
     $this->set('plugin', Router::getParam('plugin'));
     $this->set('controller', Router::getParam('controller'));
     $this->set('action', Router::getParam('action'));
     return parent::__construct($request, $response);
 }
 public function afterFind($results, $primary = false)
 {
     array_walk($results, function (&$item) {
         if (isset($item[$this->alias])) {
             $item[$this->alias]['evento'] = html_entity_decode($item[$this->alias]['evento'], ENT_QUOTES, 'UTF-8');
         }
     });
     if (in_array(Router::getParam('action'), ['cadastrar', 'index'])) {
         return $this->formatDateFields($results, $this->datesToLoad, "%a - %d/%m/%Y %H:%M");
     }
     if (Router::getParam('action') === 'exportar') {
         return $this->formatDateFields($results, $this->datesToLoad, "%d/%m/%Y %H:%M:%S");
     }
     return $results;
 }
Example #11
0
 /**
  * Constructor method
  * 
  * @param [type] $route         [description]
  * @param [type] $module        [description]
  * @param [type] $adapter       [description]
  * @param [type] $method        [description]
  * @param [type] $requestMethod [description]
  * @param [type] $regEx         [description]
  */
 public final function __construct($route, $module, $adapter, $method, $requestMethod, $regEx = [])
 {
     $this->route = $route;
     $this->module = $module;
     $this->adapter = $adapter;
     $this->method = $method;
     $this->parts = Router::getURLParts($route);
     $this->requestMethods = $requestMethod;
     $this->requestMethod = $_SERVER['REQUEST_METHOD'];
     $this->params = [];
     foreach ($this->parts as $part) {
         if (Router::isParam($part)) {
             $param = Router::getParam($part);
             $this->regEx[$param] = isset($regEx[$param]) ? $regEx[$param] : NULL;
         }
     }
 }
 function validates($options = array())
 {
     // copy the data over from a custom var, otherwise
     $actionSet = 'validate' . Inflector::camelize(Router::getParam('action'));
     if (isset($this->validationSet)) {
         $temp = $this->validate;
         $param = 'validate' . $validationSet;
         $this->validate = $this->{$param};
     } elseif (isset($this->{$actionSet})) {
         $temp = $this->validate;
         $param = $actionSet;
         $this->validate = $this->{$param};
     }
     $errors = $this->invalidFields($options);
     // copy it back
     if (isset($temp)) {
         $this->validate = $temp;
         unset($this->validationSet);
     }
     if (is_array($errors)) {
         return count($errors) === 0;
     }
     return $errors;
 }
Example #13
0
 /**
  * testGetParams
  *
  * @return void
  */
 public function testGetParams()
 {
     $paths = array('base' => '/', 'here' => '/products/display/5', 'webroot' => '/webroot');
     $params = array('param1' => '1', 'param2' => '2');
     Router::setRequestInfo(array($params, $paths));
     $expected = array('plugin' => null, 'controller' => false, 'action' => false, 'param1' => '1', 'param2' => '2');
     $this->assertEquals(Router::getParams(), $expected);
     $this->assertEquals(Router::getParam('controller'), false);
     $this->assertEquals(Router::getParam('param1'), '1');
     $this->assertEquals(Router::getParam('param2'), '2');
     Router::reload();
     $params = array('controller' => 'pages', 'action' => 'display');
     Router::setRequestInfo(array($params, $paths));
     $expected = array('plugin' => null, 'controller' => 'pages', 'action' => 'display');
     $this->assertEquals(Router::getParams(), $expected);
     $this->assertEquals(Router::getParams(true), $expected);
 }
Example #14
0
 /**
  * Allow authorization
  *
  * @param null|array|string $methods
  *
  * @return bool
  */
 public static function allowAuth($methods = null)
 {
     if (is_null($methods)) {
         return true;
     }
     $methods = array($methods);
     if (is_array($methods)) {
         if (in_array(Router::getParam("action"), $methods)) {
             return true;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
Example #15
0
 /**
  * Handshake, define relationship between chat resource_id and web authentication_id
  *
  */
 public function handshake()
 {
     $prefix = 'USER';
     if (Router::getParam('prefix', true) == 'advisor') {
         $prefix = 'ADVISOR';
     } else {
         if (Router::getParam('prefix', true) == 'admin') {
             $prefix = 'ADMIN';
         }
     }
     $authId = $prefix . '-' . AuthComponent::user('id');
     $success = $this->ChatResource->handshake($authId, $this->controller->request->data('resource_id'));
     if ($success) {
         return array('type' => 'handshake', 'resource_id' => $this->controller->request->data('resource_id'), 'auth_id' => $authId);
     }
     return array();
 }
Example #16
0
 /**
  * get current point of current user
  * 
  * @return integer
  */
 public function getCurrentPoint()
 {
     $prefix = Router::getParam('prefix', true);
     if ($prefix === 'advisor') {
         return $this->Advisor->AdvisorProfile->field('point', array('AdvisorProfile.id' => AuthComponent::user('id')));
     } else {
         return $this->User->UserProfile->field('point', array('UserProfile.id' => AuthComponent::user('id')));
     }
 }
 /**
  * common function for money and advisor_money action
  * @return void
  */
 private function __money($money = 0)
 {
     $this->loadModel('UserPointHistory');
     $prefix = Router::getParam('prefix', true);
     if ($prefix === 'advisor') {
         $currentPoint = $this->AdvisorPointHistory->getCurrentPoint($this->Auth->user('id'));
     } else {
         $currentPoint = $this->UserPointHistory->getCurrentPoint($this->Auth->user('id'));
     }
     $bankAccounts = $this->BankAccount->getListAccountOfCurrentUser();
     $money = intval($money);
     if (!isset($this->request->data['PointExchange']['point_input']) && $money) {
         $this->request->data['PointExchange']['point_input'] = $money;
     }
     $product = $this->ProductExchange->find('first', array('contain' => array('ProductCategory'), 'conditions' => array('ProductExchange.delete_flag' => 0, 'ProductCategory.delete_flag' => 0, 'ProductCategory.exchange_type' => 2), 'fields' => array('ProductExchange.id', 'ProductExchange.exchange_money_rate', 'ProductExchange.min_point_money', 'ProductExchange.money_fee', 'ProductExchange.point_fee')));
     if (empty($product)) {
         $this->redirect(array('action' => 'index'));
     }
     $viewRender = 'money';
     if ($this->request->is('post')) {
         if (!isset($this->request->data['PointExchange']['bank_account_id'])) {
             $this->redirect(array('controller' => 'bank_accounts', 'action' => 'add', $this->request->data('PointExchange.point_input')));
         }
         if (isset($this->request->data['form'])) {
             // form step
             // validate data
             $this->PointExchange->set($this->request->data);
             if ($this->PointExchange->validates()) {
                 $viewRender = 'money_confirm';
             }
         } elseif (isset($this->request->data['confirm'])) {
             // confirm step
             $this->PointExchange->create();
             $this->PointExchange->set($this->request->data);
             $pointExchange = $this->PointExchange->save();
             if ($pointExchange) {
                 if ($prefix === 'advisor') {
                     $this->AdvisorPointHistory->writeHistory('PointExchangeMoney', $pointExchange['PointExchange']['point']);
                 } else {
                     $this->UserPointHistory->writeHistory('PointExchangeMoney', $pointExchange['PointExchange']['point']);
                 }
                 $viewRender = 'money_complete';
             }
         }
     }
     $this->set(compact('product', 'currentPoint', 'bankAccounts'));
     $this->set('title_for_layout', 'ポイント交換');
     // render view according to step
     $this->render($viewRender);
 }
Example #18
0
 /**
  * Gets the current logged in user's prefix. Can be forced to default to the routed prefix parameter (if any).
  *
  * @param boolean $force Optional. Should default to routed prefix parameter or not. Defaults to false.
  * @return mixed The current requestor's or request's prefix. Empty if none can be found.
  */
 public static function currentPrefix($force = false)
 {
     $prefix = AuthComponent::user('prefix');
     if ($force && empty($prefix)) {
         $prefix = Router::getParam('prefix');
     }
     return $prefix;
 }
Example #19
0
 /**
  * testGetParams
  *
  * @return void
  */
 public function testGetParams()
 {
     $paths = array('base' => '/', 'here' => '/products/display/5', 'webroot' => '/webroot');
     $params = array('param1' => '1', 'param2' => '2');
     Router::setRequestInfo(array($params, $paths));
     $expected = array('plugin' => NULL, 'controller' => FALSE, 'action' => FALSE, 'named' => array(), 'pass' => array(), 'param1' => '1', 'param2' => '2');
     $this->assertEquals($expected, Router::getParams());
     $this->assertEquals(FALSE, Router::getParam('controller'));
     $this->assertEquals('1', Router::getParam('param1'));
     $this->assertEquals('2', Router::getParam('param2'));
     Router::reload();
     $params = array('controller' => 'pages', 'action' => 'display');
     Router::setRequestInfo(array($params, $paths));
     $expected = array('plugin' => NULL, 'controller' => 'pages', 'action' => 'display', 'named' => array(), 'pass' => array());
     $this->assertEquals($expected, Router::getParams());
     $this->assertEquals($expected, Router::getParams(TRUE));
 }