2014-02-19 94 views
-4

轉換我想這個代碼CakePHP的約定寫請幫助 這是我的PHP核心code.There的3個步驟,通過這些形式過程進行。 在步驟1中,客戶和表單的詳細信息被重定向到步驟2,在這裏添加產品,然後將數據保存到發票和產品表中。 並非所有的代碼,但如果提供一些線索如何繼續它的行動得到$步驟,並在其上做操作代碼在蛋糕的PHP

這是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> 
+4

你應該先學習MVC的原則CakePHP的使用。然後,您可以使用MVC風格分割您的代碼,並通過閱讀CakePHP的文檔,您將能夠玩會話,重定向,表單,錯誤,保存等等。我們無法幫助你,因爲你對這些知識毫無所知。 – linkyndy

回答

0

你需要一個Invoice模型誰將會關聯到您的invoices表,Invoices控制器與add方法,該方法將鏈接到您Invoice模型以保存數據庫上的數據,和一個Invoices/add視圖,這將具有以下形式用於添加發票。

登錄部分非常簡單,它的完成幾乎神奇。

爲了更好的理解,請做博客教程;你會明白的CakePHP的核心部分:http://book.cakephp.org/2.0/en/getting-started.html#blog-tutorial