1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

responseReroute or function calling? which is better?

Discussion in 'XenForo Development Discussions' started by Jaxel, Nov 5, 2010.

  1. Jaxel

    Jaxel Well-Known Member

    In my mods, I slug the minorSection string into an array and reroute my page into specific functions...

    Right now its done as follows:
    Code:
    	public function actionIndex()
    	{
    		switch ($this->slugs[0])
    		{
    			case "modules":		return $this->responseReroute(__CLASS__, 'Modules'); break;
    			case "update":		return $this->responseReroute(__CLASS__, 'Update'); break;
    			case "edit":		return $this->responseReroute(__CLASS__, 'Edit'); break;
    			case "save":		return $this->responseReroute(__CLASS__, 'Save'); break;
    			case "import":		return $this->responseReroute(__CLASS__, 'Import'); break;
    			case "export":		return $this->responseReroute(__CLASS__, 'Export'); break;
    			case "delete":		return $this->responseReroute(__CLASS__, 'Delete'); break;
    		}
    
    		return $this->responseReroute(__CLASS__, 'Portal');
    	}
    This works GREAT for me... however, I am a stickler for consistency and efficiency. In a previous thread, Mike told me that running a responseReroute will built a whole new controller object. This seems very inefficient to me...

    Theoretically, I think I could just do the following instead:
    Code:
    	public function actionIndex()
    	{
    		switch ($this->slugs[0])
    		{
    			case "modules":		return $this->actionModules(); break;
    			case "update":		return $this->actionUpdate(); break;
    			case "edit":		return $this->actionEdit(); break;
    			case "save":		return $this->actionSave(); break;
    			case "import":		return $this->actionImport(); break;
    			case "export":		return $this->actionExport(); break;
    			case "delete":		return $this->actionDelete(); break;
    		}
    
    		return $this->actionPortal();
    	}
    Would there be a downside to handling it this way? It should be more efficient shouldn't it? Since it doesn't rebuild a new controller object?
     
  2. Mike

    Mike XenForo Developer Staff Member

    It's not a particularly strenuous job making a new controller. It doesn't redo visitor setup and things like that.

    However, if you have certain preDispatch behaviors that may do things based on action (eg, permission checks), if you don't do the reroute, you won't call those. Additionally, postDispatch behaviors won't know the ultimate action that was called (for section activity tracking, for example).

    The issues are relatively minor and this is something I've debated about a bit myself, but rerouting is probably more correct for an action like that.
     
    CurveGotti likes this.
  3. Jaxel

    Jaxel Well-Known Member

    Okay... thanks mike... what about passing variables during a Reroute?

    For instance, lets say I had this inside of an actionFunction:
    Code:
    	$input = $this->_input->filter(array(
    		'submit' => XenForo_Input::STRING,
    		'preview' => XenForo_Input::STRING,
    		'delete' => XenForo_Input::STRING,
    	));
    	$input['page_content'] = $this->getHelper('Editor')->getMessageText('page_content', $this->_input);
    
    	if ($input['preview'])
    	{
    		return $this->responseReroute(__CLASS__, 'PageEdit');
    	}
    How would I pass $input along with the responseReroute to actionPageEdit?
     
  4. Mike

    Mike XenForo Developer Staff Member

    That is a pain and something that I haven't figured out an ideal solution for. I have occasionally just pushed things into $this->_request using setParam() and read getUserParam().
     

Share This Page