在Cake Php中转换的代码

时间:2014-02-19 12:14:14

标签: cakephp

我想用CakePhp约定编写这段代码请帮忙 这是我的核心PHP代码。表单进程有3个步骤。 在步骤1中,客户端和表单的详细信息将重定向到第2步,此处添加产品,然后将数据保存到发票和产品表中。 不是所有的代码,但如果提供了一些线索,如何在行动中继续它获取$步骤并对其进行操作

这是add.php

<?
include "inc/functions.php";

if(!$_SESSION['logged']){
header("Location: login/");
}
$meniu='add';
$step=1;
    if(isset($_GET['step'])){
        $step=$_GET['step'];
    }

    if(isset($_POST['step1'])){
    if($_POST['client_name']==''){
        $err['client_name']='error';
    }else{
        $_SESSION['order']['client_name']=$_POST['client_name'];
        $_SESSION['order']['client_email']=$_POST['client_email'];
        $_SESSION['order']['client_phone']=$_POST['client_phone'];
        $_SESSION['order']['client_address']=$_POST['client_address'];
        $_SESSION['order']['client_location']=$_POST['client_location'];
        $_SESSION['order']['payment_method']=$_POST['payment_method'];
        header("Location: add.php?step=2");
    }
    }       

    if(isset($_POST['step2'])){
        mysql_query("insert into       invoices(client_name,client_email,client_phone,client_address,client_location,payment_metho    d,vat,total,currency,date) values('".$_SESSION['order']    ['client_name']."','".$_SESSION['order']['client_email']."','".$_SESSION['order']['client_phone']."','".$_SESSION['order']['client_address']."','".$_SESSION['order']['client_location']."','".$_SESSION['order']['payment_method']."','".$cfg['vat']."','".$_SESSION['total_order']."','".$cfg['currency']."','".time()."')")or die(mysql_error()."1");
            $id=mysql_insert_id();

        foreach($_SESSION['products'] as $tag=>$val){
            mysql_query("insert into products(title,description,qty,price,taxes,invoice) values('".$val['title']."','".$val['description']."','".$val['qty']."','".$val['price']."','".$val['taxes']."','".$id."')")or die(mysql_error()."2");
        }

        unset($_SESSION['products'],$_SESSION['order']);
        $_SESSION['invoice']=$id;
        header("Location: add.php?step=3");
    }
?>
<body>
<div id='container'>
  <? include "inc/header.php"?>
  <div class='title'>New Invoice</div>
  <div id='step'>
<table align='center'>
  <tr>
    <td class='step <? if($step==1){?>current<? }elseif($step>1){?>done<? }?>'>Setup Client</td>
    <td class='step <? if($step==2){?>current<? }elseif($step>2){?>done<? }?>'>Add Products</td>
    <td class='step <? if($step==3){?>current<? }elseif($step>3){?>done<? }?>'>Save/Export</td>
  </tr>
</table>
  </div>
  <div id='content'>
    <?
        if($step==1){include "inc/step1.php";}
        if($step==2){include "inc/step2.php";}
        if($step==3){include "inc/step3.php";}
        ?>
  </div>
    </div>
    <? include "inc/footer.php"?>
   </body>

1 个答案:

答案 0 :(得分:0)

您需要一个Invoice模型,该模型将与您的invoices表关联,Invoices控制器使用add方法,该方法将链接到您的Invoice用于保存数据库数据的模型,以及一个Invoices/add视图,其中包含添加发票的表单。

登录部分非常简单,几乎神奇地完成了。

为了更好地理解,请参阅博客教程;您将了解CakePHP的核心部分:http://book.cakephp.org/2.0/en/getting-started.html#blog-tutorial