保存之前显示setFlash

时间:2019-05-03 21:24:38

标签: php cakephp cakephp-2.0

我有一个cakephp Web应用程序,并且出于某些原因,对于此特定的控制器检出功能(具有一些输入和产品列表的视图),由于某种原因,我打算在保存数据后显示的setFlash无法正常工作它应该是。如果保存成功,它应该显示在indexstock.ctp视图上,这是我要重定向用户的位置,但是它将加载到此checkout.ctp视图中。我已经无数次地查看了此代码,尽管该函数具有典型的逻辑,但rsetflash和redirect的部分与我在该项目的所有其他函数中使用的相同,因此无法找到错误的出处。

这是我的功能:

public function checkout() {

$this->loadModel('Sale');
if (!empty($this->data)) 
{
    $this->Sale->create();  
    if ($this->Sale->save($this->data)) 
    {

    session_start();
    foreach($_SESSION["shopping_cart"] as $values)
        {   
            $this->Sale->ProductsSale->create();
            $this->Sale->ProductsSale->saveField('sale_id', $this->Sale->id);
            $this->Sale->ProductsSale->saveField('product_id', $values['product_id']);
            $this->Sale->ProductsSale->saveField('cant', $values['product_quantity']);
            $this->Sale->ProductsSale->saveField('price', $values['product_price']);

            $this->Sale->ProductsSale->saveField('shipping_id', $values['product_shipping']);



        $this->Product->ProductsShipping->id = $values['product_psid'];
        $this->Product->ProductsShipping->saveField('sold',$values['product_quantity']);


        }
    $this->Sale->Transaction->create();
    $this->Sale->Transaction->saveField('date',$this->data['Sale']['date']);
    $this->Sale->Transaction->saveField('concept',$this->data['Sale']['details']);
    $this->Sale->Transaction->saveField('sign','+');
    $this->Sale->Transaction->saveField('amount',$_SESSION["total_price"]);
    $this->Sale->Transaction->saveField('sale_id', $this->Sale->id);


    unset($_SESSION["shopping_cart"]);
    //THIS GUY HERE IS THE ONE NOT BEHAVING CORRECTLY
    $this->Session->setFlash('<strong>Exito!</strong> El producto se ha guardado', 'Flash/success');
    $this->redirect(array('action'=>'indexstock'),null, true);
    } else {
        $this->Session->setFlash('<strong>Error!</strong> El producto no se ha guardado', 'Flash/error');
    }
}
$clients = $this->Sale->Client->find('list');
$this->set(compact('clients'));
}

如何解决此问题?

0 个答案:

没有答案