mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-02-06 15:14:58 +00:00
get action from request, run hook preRun and check for return value
This commit is contained in:
parent
1cce969ba7
commit
8ceb8d1e6a
|
@ -48,24 +48,38 @@ class SeedDMS_Controller_Common {
|
|||
}
|
||||
|
||||
/**
|
||||
* Call methods with name in $get['action']
|
||||
* Call method with name in $get['action']
|
||||
*
|
||||
* @params array $get $_GET or $_POST variables
|
||||
* Until 5.1.26 (6.0.19) this method took the name of the
|
||||
* controller method to run from the element 'action' passed
|
||||
* in the array $get. Since 5.1.27 (6.0.20) a PSR7 Request
|
||||
* object is available in the controller and used to get the
|
||||
* action.
|
||||
*
|
||||
* @params array $get $_GET or $_POST variables (since 5.1.27 this is no longer used)
|
||||
* @return mixed return value of called method
|
||||
*/
|
||||
function __invoke($get=array()) {
|
||||
if(!$this->callHook('preRun', get_class($this), isset($get['action']) ? $get['action'] : 'run', $get)) {
|
||||
if(isset($get['action']) && $get['action']) {
|
||||
if(method_exists($this, $get['action'])) {
|
||||
return $this->{$get['action']}();
|
||||
$action = null;
|
||||
$request = $this->getParam('request');
|
||||
if($request) {
|
||||
if($request->isMethod('get'))
|
||||
$action = $request->query->get('action');
|
||||
elseif($request->isMethod('post'))
|
||||
$action = $request->request->get('action');
|
||||
}
|
||||
if(!$this->callHook('preRun', get_class($this), $action ? $action : 'run')) {
|
||||
if($action) {
|
||||
if(method_exists($this, $action)) {
|
||||
return $this->{$action}();
|
||||
} else {
|
||||
echo "Missing action '".$get['action']."'";
|
||||
echo "Missing action '".$action."'";
|
||||
return false;
|
||||
}
|
||||
} else
|
||||
return $this->run();
|
||||
}
|
||||
$this->callHook('postRun', get_class($this), isset($get['action']) ? $get['action'] : 'run', $get);
|
||||
$this->callHook('postRun', get_class($this), $action ? $action : 'run');
|
||||
}
|
||||
|
||||
function setParams($params) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user