I'm looking proper way to revert any given redirect command in ZF2 controller
For example in one of my function i use - $this->redirect()->toRoute('my/desire/path/to/redirect'); But after getting result I want to cancel that command and show something else to my user.
Here is my code to illustrate more precisely -
considering following method inside controller that will retrieve data for one id
public function getMyData(){
$idX = $this->params()->fromRoute('id');
$rtrn=$this->myTableGateway->getData($idX);
if($rtrn!==false){
$mnfctr['myData']=$rtrn;
$mnfctr['readMode']='yes';
return $mnfctr;
}else return $this->redirect()->toRoute('product-loader/sub-categories', array('cid'=>$this->mcep->id));
}
now in a real action inside controller
public function readAction(){
$data=$this->getMyData();
if($data instanceof \Zend\Http\PhpEnvironment\Response) return $data;
# do rest of the staff of read action
}
public function deleteAction(){
$data=$this->getMyData();
if($data instanceof \Zend\Http\PhpEnvironment\Response) return $data;
# do rest of the staff of delete action
}
now i want to show a logo of my company through the same controller problem is if i simply redirect the logo should not draw properly so i design my image action method as follows
public function logoAction(){
$logoFlName='Unknown Company';
$data=$this->getMyData();
#echo '$mnfctr: '.get_class($mnfctr); exit();
$response = $this->getResponse();
if($mnfctr instanceof \Zend\Http\PhpEnvironment\Response){
# in this situation i need to cancel my previous response command
$logoFlName='Invalid Company';
if($response->isRedirect()){
$this->flashMessenger()->clearCurrentMessages();
$response->getHeaders()->clearHeaders();
$response->setStatusCode(Response::STATUS_CODE_200);
}
}elseif(is_array($data) && array_key_exists('myData', $data) && $data['myData'] instanceof MyData){
# code to draw the real logo
$logoFlName='Logo of XYZ Company';
}else{ /* something wrong and can't be happen. but we really can't find logo */ }
$newImage=PLImageHelper::getLogoFromString($string2draw__not_found_image__or__logo);
$response->setContent($newImage->get('png'));
$response->getHeaders()
->addHeaderLine('Content-Transfer-Encoding', 'binary')
->addHeaderLine('Content-Type', 'image/png')
->addHeaderLine('Content-Disposition', 'filename="'.$logoFlName.'.png"')
#->addHeaderLine('Content-Length', mb_strlen($imageContent))
;
return $response;
}
I know there has a lot of way, suppose its possible to redirect to a real no-image-found.png file to show. but i want it programmatically