gpt4 book ai didi

javascript - 如何将 php 文件转换为 codeigniter

转载 作者:行者123 更新时间:2023-11-29 07:22:07 25 4
gpt4 key购买 nike

我需要帮助将此代码转换为 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;
}
}
}

?>

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

最佳答案

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

您必须执行以下步骤:

第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 步:创建 Controller 示例 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 View

<!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>

关于javascript - 如何将 php 文件转换为 codeigniter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35765191/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com