コード例 #1
0
 /**
  * Override runWithParams() implementation in CAction to help us parse
  * requests with subactions.
  *
  * @param array $params URL Parameters
  */
 public function runWithParams($params)
 {
     // Default method that would be called if the subaction and run() do not exist
     $sDefault = 'index';
     // Check for a subaction
     if (empty($params['sa'])) {
         $sSubAction = $sDefault;
         // default
     } else {
         $sSubAction = $params['sa'];
     }
     // Check if the class has the method
     $oClass = new ReflectionClass($this);
     if (!$oClass->hasMethod($sSubAction)) {
         // If it doesn't, revert to default Yii method, that is run() which should reroute us somewhere else
         $sSubAction = 'run';
     }
     // Populate the params. eg. surveyid -> iSurveyId
     $params = $this->_addPseudoParams($params);
     if (!empty($params['iSurveyId'])) {
         if (!Survey::model()->findByPk($params['iSurveyId'])) {
             Yii::app()->setFlashMessage(gT("Invalid survey ID"), 'error');
             $this->getController()->redirect(array("admin/index"));
         } elseif (!Permission::model()->hasSurveyPermission($params['iSurveyId'], 'survey', 'read')) {
             Yii::app()->setFlashMessage(gT("No permission"), 'error');
             $this->getController()->redirect(array("admin/index"));
         } else {
             LimeExpressionManager::SetSurveyId($params['iSurveyId']);
             // must be called early - it clears internal cache if a new survey is being used
         }
     }
     // Check if the method is public and of the action class, not its parents
     // ReflectionClass gets us the methods of the class and parent class
     // If the above method existence check passed, it might not be neceessary that it is of the action class
     $oMethod = new ReflectionMethod($this, $sSubAction);
     // Get the action classes from the admin controller as the urls necessarily do not equal the class names. Eg. survey -> surveyaction
     $aActions = Yii::app()->getController()->getActionClasses();
     if (empty($aActions[$this->getId()]) || strtolower($oMethod->getDeclaringClass()->name) != strtolower($aActions[$this->getId()]) || !$oMethod->isPublic()) {
         // Either action doesn't exist in our whitelist, or the method class doesn't equal the action class or the method isn't public
         // So let us get the last possible default method, ie. index
         $oMethod = new ReflectionMethod($this, $sDefault);
     }
     // We're all good to go, let's execute it
     // runWithParamsInternal would automatically get the parameters of the method and populate them as required with the params
     return parent::runWithParamsInternal($this, $oMethod, $params);
 }
コード例 #2
0
 /**
  * Override runWithParams() implementation in CAction to help us parse
  * requests with subactions.
  *
  * @param array $params URL Parameters
  */
 public function runWithParams($params)
 {
     // Default method that would be called if the subaction and run() do not exist
     $sDefault = 'index';
     // Check for a subaction
     if (empty($params['sa'])) {
         $sSubAction = $sDefault;
         // default
     } else {
         $sSubAction = $params['sa'];
     }
     // Check if the class has the method
     $oClass = new ReflectionClass($this);
     if (!$oClass->hasMethod($sSubAction)) {
         // If it doesn't, revert to default Yii method, that is run() which should reroute us somewhere else
         $sSubAction = 'run';
     }
     // Populate the params. eg. plid -> iSurveyId
     $params = $this->_addPseudoParams($params);
     if (!empty($params['iPanellistId'])) {
         if (!PL::model()->findByPk($params['iPanellistId'])) {
             $this->getController()->error('Invalid panel-list id');
         } elseif (!PL::model()->IsValid($params['iPanellistId'])) {
             $this->getController()->error('Not active');
         } else {
         }
     }
     // Check if the method is public and of the action class, not its parents
     // ReflectionClass gets us the methods of the class and parent class
     // If the above method existence check passed, it might not be neceessary that it is of the action class
     $oMethod = new ReflectionMethod($this, $sSubAction);
     // Get the action classes from the admin controller as the urls necessarily do not equal the class names. Eg. survey -> surveyaction
     $aActions = Yii::app()->getController()->getActionClasses();
     if (empty($aActions[$this->getId()]) || strtolower($oMethod->getDeclaringClass()->name) != $aActions[$this->getId()] || !$oMethod->isPublic()) {
         // Either action doesn't exist in our whitelist, or the method class doesn't equal the action class or the method isn't public
         // So let us get the last possible default method, ie. index
         $oMethod = new ReflectionMethod($this, $sDefault);
     }
     // We're all good to go, let's execute it
     // runWithParamsInternal would automatically get the parameters of the method and populate them as required with the params
     return parent::runWithParamsInternal($this, $oMethod, $params);
 }