I'm trying to use CakePhp and JQuery Mobile combined. Generally it works great, but i've got a huge problem with using the Redirect from One Controller to a different.
Espacially since i added the RequestHandler.
I think the problem in this case is that, Jquery Mobile is expecting a whole page string but the controller is just giving the view back.
Is there any way to make the redirect function working, with jquery mobile?
In this case I like to redirect from Orderheads to the Orderpositions
Controller Orderheads
if ($this->request->is ( 'post' )) {
$this->Orderhead->create ();
if ($this->Orderhead->saveAll ( $this->request->data,array (
'deep' => true
))) {
$orderId = $this->Orderhead->findByOrdernumber( $this->request->data['Orderhead']['ordernumber']);
$id =$orderId['Orderhead']['id'];
$this->Session->setFlash ( __ ( 'The orderhead has been saved.' ) );
return $this->redirect ( array (
'controller' => 'orderpositions',
'action' => 'add', $id
) );
} else {
$this->Session->setFlash ( __ ( 'The orderhead could not be saved. Please, try again.' ) );
}
}
Controller Orderpositions
public $components = array (
'Paginator',
'Session',
'RequestHandler'
);
public function add($id = null) {
if ($this->request->is ( 'ajax' )) {
if ($this->RequestHandler->isAjax ()) {
Configure::write ( 'debug', 0 );
}
if (! empty ( $this->data )) {
$this->autoRender = false;
$this->Orderposition->create ();
if ($this->Orderposition->save ( $this->request->data )) {
echo 'Record has been added';
} else {
echo 'Error while adding record';
}
}
} else {
$this->loadModel ( 'Orderhead' );
if ($this->Orderhead->exists ( $id )) {
$orderInformation = $this->Orderhead->findById ( $id );
} else {
throw new NotFoundException ( __ ( 'Invalid order id does not exists' ) );
}
$this->set ( compact ( 'orderInformation' ) );
}
}