我正在尝试结合使用 CakePhp 和 JQuery Mobile。通常它工作得很好,但是我在使用从一个控制器重定向到另一个控制器时遇到了一个巨大的问题。
特别是因为我添加了 RequestHandler。
我认为在这种情况下的问题是,Jquery Mobile 需要一个完整的页面字符串,但控制器只是返回视图。
有什么方法可以使重定向功能与jquery mobile一起工作?
在这种情况下,我喜欢从 Orderheads 重定向到 Orderpositions
控制器订单头
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.' ) );
}
}
控制器订单位置
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' ) );
}
}