duanlian1978 2019-05-03 21:24
浏览 35

我保存之前显示的setFlash

I have a cakephp web app, and for this specific controller checkout function (which is a view with some inputs and a list of products) for some reason the setFlash I intend to show after the data is saved isn't working as it should be. It should show on the indexstock.ctp view which is where I'm redirecting the user if save is successfully but instead it gets loaded on this very checkout.ctp view. I've reviewed this code countless times and can't find where the error is, despite the atipical logic of this function the rsetflash and redirect part is the same I use on every other function of this project.

This is my function:

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'));
}

How do I solve this problem?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭
    • ¥15 2020长安杯与连接网探
    • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
    • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
    • ¥15 可见光定位matlab仿真
    • ¥15 arduino 四自由度机械臂
    • ¥15 wordpress 产品图片 GIF 没法显示