2016-03-03 42 views
0

我需要幫助把這段代碼轉換到笨MVC我有3個文件,PHP Openlink3.php爲觀衆class.php類和databaseConnection.php爲模型如何轉換PHP文件笨

我有問題這個轉換php文件到codeigniter。請幫幫我。

這是我的PHP代碼Openlink.php

<?php 
include("DatabaseConnection.php"); 
include("class.php"); 

Global $AppCode; 
//$AppCode='0001'; 
$user='0772'; 

$db = new dbconnection(); 
$conn = $db->dbOpen(); 

$misApp = new misApplication(); 

$sql="SELECT a.RAL_Code,a.RAL_App_Name,a.RAL_Remarks,b.RAL_APPIconLocation,b.RAL_ApplicationLink FROM R_Application_List as a ,R_Application_Links as b where a.RSC_Active=1 and a.RAL_Code=b.RAL_APPCODE"; 
     $rs=odbc_exec($conn,$sql); 
     $appcount; 
     echo "<table align=center cellpadding=10>"; 
     echo "<tr height=120>"; 
     $appcount=0; 
     while (odbc_fetch_row($rs)) 
     { 
      $appcode=odbc_result($rs,"RAL_Code"); 
      $appname=odbc_result($rs,"RAL_App_Name"); 
      $desc=odbc_result($rs,"RAL_Remarks"); 
      $icon=odbc_result($rs,"RAL_APPIconLocation"); 
      $applink=trim(odbc_result($rs,"RAL_ApplicationLink")); 



      if($appcount==3){ 
      echo "<tr height=120>"; 
      //echo "<td>"; 

      $appcount=0; 
      } 
      //echo "<td>".$appcode."</td>"; 
      //echo "<td>".$appname."</td>"; 
      echo "<td valign=bottom><img src=".$icon."height=30 width=150 onclick='openApp(\"$appcode\",\"$user\",\"$applink\");' </img></td>"; 
      //echo "<td><input type=\"button\" ></td>" 
      //echo "<td>".$desc."</td>"; 
      echo '<script>openApp();</script>'; 

      $appcount++; 
      //echo $icon."<br/>"; 

     } 
     echo "</table>"; 
?> 

<img src="dtr.png" height="30" width="150" onclick=openApp("0001","<?php echo $user; ?>","<?php echo $appLink = $misApp->getAppLink($conn,"0001",$user); ?>") ></img></br> 
<input type="button" id="btn.DTR"; name="btn.Dtr"; value="DTR"; onclick='openApp("0001","<?php echo $user; ?>","<?php echo $appLink = $misApp->getAppLink($conn,"0001",$user); ?>")'/> 

<input type="button" id="jose"; name="btn.OpenApp"; value="Approval System(test)"; background="dtr.png";onclick='openApp("0014","<?php echo $user; ?>","<?php echo $appLink = $misApp->getAppLink($conn,"0002",$user); ?>")'/> 

<script language="javascript"> 
function openApp(Appcode, User, link){ 

var OpenLink; 

OpenLink = link+"?A1="+User+"&A2="+Appcode; // Concatenating strings 
//alert(OpenLink); 

//document.write (OpenLink); // printing the Concatenated string 

//window.open(OpenLink); 
//window.open(OpenLink,'_blank', 'toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,left=10000, top=10000, width=10, height=10, visible=none', ''); 
window.location.href = OpenLink; 

} 
</script> 

</html> 

這是我的PHP代碼class.php

<?php 

class misApplication{ 

    public function getAppLink($actveConn,$appCode,$user){ 
     $linktoOpen; 
     $sql="select * from R_Application_Links where RAL_APPCode='$appCode'"; 
     $rs=odbc_exec($actveConn,$sql); 

     while (odbc_fetch_row($rs)) 
     { 
      $a=odbc_result($rs,"RAL_APPCode"); 
      $b=odbc_result($rs,"RAL_InstallationLink"); 
      $link=odbc_result($rs,"RAL_ApplicationLink"); 
      $d=odbc_result($rs,"RAL_APPIconLocation"); 
     } 
     $linktoOpen = $link.$user.$appCode; 
     return trim($link); 

     odbc_close($actveConn); 

    } 
} 
?> 

DatabaseConnection.php

<?php 

class dbconnection{ 

    public function dbOpen(){ 
     $conn=odbc_connect("Global02","USER-00","USER00"); 
     if (!$conn){ 
      exit("Connection Failed: " . $conn); 
     } 
     else{ 
      return $conn; 
     } 
    } 
} 

?> 

當我轉換它,它總是有一個錯誤。

+0

檢查CodeIgniter用戶指南 –

+0

的數據庫您使用的? – sintakonte

回答

2

你必須遵循簡單的步驟,您可以根據需要先檢查用戶指南,反正試試這個

你必須遵循以下步驟:

步驟1:對於數據庫連接 在database.php 設置裏面$db['default']

數據庫配置使用加載數據庫autoload.php

$autoload['libraries'] = array('database'); 

步驟2: 創建模型實例Mdl_mis.php

實施例:

<?php 
defined('BASEPATH') OR exit('No direct script access allowed'); 

class Mdl_mis extends CI_Model { 
    function getAllApplink(){ 
     $this->db->select("SELECT a.RAL_Code,a.RAL_App_Name,a.RAL_Remarks,b.RAL_APPIconLocation,b.RAL_ApplicationLink"); 
     $this->db->from("R_Application_List as a"); 
     $this->db->join("R_Application_Links as b","a.RAL_Code=b.RAL_APPCODE",'INNER'); 
     $this->db->where("a.RSC_Active",1); 
     $result = $this->db->get()->result_array(); 
     return $result; 
    } 


    function getAppLink($appCode,$user){ 
     $this->db->select("*"); 
     $this->db->from("R_Application_Links"); 
     $this->db->where("RAL_APPCode",$appCode); 
     $result = $this->db->get()->row_array(); 

     $a = $result['RAL_APPCode']; 
     $b = $result['RAL_InstallationLink']; 
     $link = $result['RAL_ApplicationLink']; 
     $d = $result['RAL_APPIconLocation']; 

     $linktoOpen = $link.$user.$appCode; 
     return trim($link); 
    } 

} 
?> 

步驟3: 創建控制器例如MisApplication.php 創建一個方法還

示例:

<?php 
defined('BASEPATH') OR exit('No direct script access allowed'); 

class MisApplication extends CI_Controller { 
    public function index() 
    { 
     /* Load you model first */ 
     $this->load->model('Mdl_mis'); 
     $data['all_link'] = $this->Mdl_mis->getAllApplink(); 
     /* Create one view called index.php and load it and pass your data*/ 
     $this->load->view('index',$data); 
    } 

} 
?> 

步驟4:把代碼index.php視圖

<!DOCTYPE html> 
<html> 
<body> 
     <table align=center cellpadding=10>"; 
     <tr height=120>"; 
<?php 
     $appcount=0; 
     foreach($all_link as $rs)) 
     { 
      $appcode = $rs["RAL_Code"]; 
      $appname = $rs["RAL_App_Name"]; 
      $desc = $rs["RAL_Remarks"]; 
      $icon = $rs["RAL_APPIconLocation"]; 
      $applink = trim($rs["RAL_ApplicationLink"]); 

      if($appcount==3){ 
      echo "<tr height=120>"; 
      //echo "<td>"; 

      $appcount=0; 
      } 

      //echo "<td>".$appcode."</td>"; 
      //echo "<td>".$appname."</td>"; 
      echo "<td valign=bottom><img src=".$icon."height=30 width=150 onclick='openApp(\"$appcode\",\"$user\",\"$applink\");' </img></td>"; 
      //echo "<td><input type=\"button\" ></td>" 
      //echo "<td>".$desc."</td>"; 
      echo '<script>openApp();</script>'; 
      $appcount++; 

     } 
     echo "</table>"; 
?> 

<img src="dtr.png" height="30" width="150" onclick=openApp("0001","<?php echo $user; ?>","<?php echo $appLink = $this->Mdl_mis->getAppLink("0001",$user); ?>") ></img></br> 
<input type="button" id="btn.DTR"; name="btn.Dtr"; value="DTR"; onclick='openApp("0001","<?php echo $user; ?>","<?php echo $appLink = $this->Mdl_mis->getAppLink("0001",$user); ?>")'/> 

<input type="button" id="jose"; name="btn.OpenApp"; value="Approval System(test)"; background="dtr.png";onclick='openApp("0014","<?php echo $user; ?>","<?php echo $appLink = $this->Mdl_mis->getAppLink("0002",$user); ?>")'/> 

<script language="javascript"> 
function openApp(Appcode, User, link){ 

var OpenLink; 

OpenLink = link+"?A1="+User+"&A2="+Appcode; // Concatenating strings 
//alert(OpenLink); 

//document.write (OpenLink); // printing the Concatenated string 

//window.open(OpenLink); 
//window.open(OpenLink,'_blank', 'toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,left=10000, top=10000, width=10, height=10, visible=none', ''); 
window.location.href = OpenLink; 

} 
</script> 

</html>