当前位置:首页 > 开发 > 编程语言 > PHP > 正文

PHP订单操作 serialize

发表于: 2012-12-05   作者:dcj3sjt126com   来源:转载   浏览次数:
摘要:   <input type="hidden" name="rqInfo" value='<?php echo serialize ($sessRequire);?>'> ************** Action //添加订单行信息 function addRequireLine ($mapping, $

 

<input type="hidden" name="rqInfo" value='<?php echo serialize ($sessRequire);?>'>
**************
Action
//添加订单行信息
    function  addRequireLine ($mapping, $form, &$request, &$response){ 
        $arr_rq_info = $request->getParameter('rqInfo');//提交序列化订单信息来更新
        if(MAGIC_QUOTES_GPC){
            $require_info= stripslashes($arr_rq_info);
        }
    $require_info= unserialize ($arr_rq_info);
        if(!$require_info){
            $require_info =  array(
                'prj_id'      => null,
                'ref'          => null, 
                'create_time' => null,
                'building'      => null, //以上是存订单头信息
                'lineItems'   => array(),  //添加lineItems的index放订单行信息
            );
        }
        $option = $request->getParameter('option');
        $aryRq = $form->aryRequireJob;//订单头信息
        $aryRqLines = $form->aryRequireLines;////订单行信息
        $rqInfo = $this->delegate->addRequireJobLine($aryRq, $option, $aryRqLines, $require_info);
        $form->setSessRequire($rqInfo); //将更新后订单信息传到页面
        $this->init ($mapping, $form, &$request, &$response);

        $request->setAttribute('ACTION_FORM',$form);
        return $mapping->findForwardConfig('success');        
    }
//编辑订单行信息
    function  editRequireLine ($mapping, $form, &$request, &$response){
        $arr_rq_info = $request->getParameter('rqInfo');
        $require_info = unserialize($arr_rq_info);

        $lineNo = $request->getParameter('num');
        $option = $request->getParameter('option');
        $aryRq = $form->aryRequireJob;
        $aryRqLines = $form->aryRequireLines;
        if($require_info){
            $rqInfo = $this->delegate->editRequireJobLine($lineNo, $option, $aryRq, $aryRqLines, $require_info);
        }
        $form->setSessRequire($rqInfo);
        $this->init ($mapping, $form, &$request, &$response);
        
        $request->setAttribute('ACTION_FORM',$form);
        return $mapping->findForwardConfig('success');
    }
******manager********
    function addArrayRequireLine($aryRequire, $option, $aryRequireLines, $rqInfo){
            $rqInfo['prj_id']     = $aryRequire['prj_id'];
            $rqInfo['ref']         = $aryRequire['ref'];
            $rqInfo['create_time'] = $aryRequire['create_time'];
            $rqInfo['building']     = $aryRequire['building'];
            array_push($rqInfo['lineItems'],array(
                    'stock_code'    => $aryRequireLines['stock_code'],
                    'stock_name'    => $aryRequireLines['stock_name'],
                    'stock_detail'  => $aryRequireLines['stock_detail'],
                    'supplier_name' => $aryRequireLines['supplier_name'],
                    'building'        => $aryRequireLines['building'],
                    'delivery_to'    => $aryRequireLines['delivery_to'],
                    'qty'            => $aryRequireLines['qty'],
                    'remark'        => $aryRequireLines['remark']
                )
            );
            return $rqInfo;
    }
 
    function editArrayRequireLine($lineNo, $option, $aryRequire, $aryRequireLines, $rqInfo){
             $rqInfo['prj_id']         = $aryRequire['prj_id'];
             $rqInfo['ref']             = $aryRequire['ref'];
             $rqInfo['create_time']  = $aryRequire['create_time'];
             $rqInfo['building']     = $aryRequire['building'];
             $rqInfo['lineItems'][$lineNo]['stock_code']   = $aryRequireLines['stock_code'];
             $rqInfo['lineItems'][$lineNo]['stock_name']   = $aryRequireLines['stock_name'];
             $rqInfo['lineItems'][$lineNo]['stock_detail'] = $aryRequireLines['stock_detail'];
             $rqInfo['lineItems'][$lineNo]['supplier_name']= $aryRequireLines['supplier_name'];
             $rqInfo['lineItems'][$lineNo]['building']       = $aryRequireLines['building'];
             $rqInfo['lineItems'][$lineNo]['delivery_to']  = $aryRequireLines['delivery_to'];
             $rqInfo['lineItems'][$lineNo]['qty']           = $aryRequireLines['qty'];
             $rqInfo['lineItems'][$lineNo]['remark']       = $aryRequireLines['remark'];
            return $rqInfo;
    }   
 
    function deleteArrayRequireLine($lineNo, $rqInfo){
            unset($rqInfo['lineItems'][$lineNo]);
            return $rqInfo;
    }

    function replace_require_index($LineNo, $LineNoAfter, $rqInfo){
            $rqInfo['lineItems'][$LineNo]= $rqInfo['lineItems'][$LineNoAfter];
            deleteArrayRequireLine($LineNoAfter,  $rqInfo){
            return $rqInfo;
    }
*******delegate*****
    function addRequireJobLine($aryRequire, $option, $aryRequireLines, $rqInfo){
        return $this->data_manager->addArrayRequireLine($aryRequire, $option, $aryRequireLines, $rqInfo);
    }
 
    function editRequireJobLine($lineNo, $option, $aryRequire, $aryRequireLines, $rqInfo){
        return $this->data_manager->editArrayRequireLine($lineNo, $option, $aryRequire, $aryRequireLines, $rqInfo);
    }
//删除订单行后,重组数组key(数组key对应的是订单行号信息,所以要重组)
    function deleteOutRqJobLine($lineNo, $lineCounter, $rqInfo){
        if(($lineNo+1)==$lineCounter){
            $rqInfo = $this->data_manager->deleteOutRequireLine($lineNo, $rqInfo);
        }
        if(($lineNo+1)<$lineCounter){
            $rqInfo = $this->data_manager->deleteOutRequireLine($lineNo, $rqInfo);
            for($i=($lineNo+1);$i<$lineCounter;$i++){
                $rqInfo = $this->data_manager->replace_outrq_index(($i-1), $i, $rqInfo);
            }            
        }
         return $rqInfo;
    }

 

方法二:将订单行的操作与不做交互,用js去更新页面值。点击保存订单存数据库,才做交互,方法二较一要好http://hudeyong926.iteye.com/admin/blogs/608030

PHP订单操作 serialize

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

编辑推荐
根据存储的内容来划分 字符串: file_put_contents :将一个字符串写入文件 语法:int file_put_con
  serialize()序列化表单元素为字符串,用于 Ajax 请求。   serializeArray()序列化表单元素为J
安装MongoDB可以参照我的C#操作MongoDB那篇文章。 php的话首先从网上下载MongoDB的扩展包,https://
安装MongoDB可以参照我的C#操作MongoDB那篇文章。 php的话首先从网上下载MongoDB的扩展包,https://
JSON 是一个轻量级的文本数据交换格式,他比 XML 更小、更快,更易解析,所以在PHP开发过程中,我们
Mongodb的常用操作 参看手册,php官方的http://us2.php.net/manual/en/mongo.manual.php 也可以参看
Mongodb的常用操作 参看手册,php官方的http://us2.php.net/manual/en/mongo.manual.php 也可以参看
Mongodb的常用操作 参看手册,php官方的http://us2.php.net/manual/en/mongo.manual.php 也可以参看
$array = array ('A', 'B', 'C' ); //使用int array_unshift(array $array,mixed variable[,mixed v
本文章根据: http://us.php.net/manual/en/class.mongocollection.php http://www.cnblogs.com/xffy
版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号