0

我需要帮助将此代码转换为 codeigniter MVC 我有 3 个文件 php Openlink3.php 用于查看器 class.php 用于类和 databaseConnection.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);

    }
}
?>

数据库连接.php

<?php

class dbconnection{

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

?>

当我转换它时,它总是有错误。

4

1 回答 1

2

您必须遵循的简单步骤,您可能需要先查看用户指南,无论如何试试这个

您必须按照以下步骤操作:

Step 1 : For database connection 在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>
于 2016-03-03T07:31:41.450 回答