如何将 codeigniter 脚本嵌入到外部 php 脚本中
How to embed codeigniter script into external php script
我在
中有我网站的索引文件
localhost-->mywebsite-->index.php
(这是我的外部脚本)
我已经用 codeigniter 建立了一个注册表。
我可以使用注册表单 url http://localhost/codeigniter/index.php/form。
但是我怎样才能将该注册表附加到我的网站索引文件中。
在我的外部 php 脚本(我网站的index.php
)中使用 include_once"../codeigniter/index.php/form";
无效。
但是,如果我将 'form'
作为默认控制器文件并使用来自外部 php 脚本的以下代码
include_once "codeigniter/index.php";
效果很好。但是如果我需要其他控制器文件而不仅仅是 'form'
怎么办?
更新:
我还可以从外部 php 脚本 link 到该文件,如下所示:
<a href="codeigniter/index.php/form>Register</a>.
但不包括。每当我包括它显示没有这样的文件。
在 localhost-->mywebsite-->index.php,你可以试试这个:
<?php include_once('/codeigniter/index.php/form'); ?>
如果没有,您可以将您的 index.php 代码移动到 codeigniter 视图中并以这种方式进行设置。
因此,如果我理解正确的话,您想在其他 php 网站上使用 codeigniter's
表单,实际上这样做的想法是 错误的 (因为你通常无法控制你的表单操作 link 等更好地直接在其他网站上构建相同的),但你的问题的答案是遵循技巧
将此代码放在您希望包含 codeigniter 表单的其他网站中
$output = shell_exec('php ABSOLUTE_PATH/codeigniter/index.php form index');
// where "ABSOLUTE_PATH" is absolute path to your codeigniter project
// "form" is your controller name
// "index" action name
echo $output; // will echo form html generated by codeigniter
尝试使用下面的代码...
<?php $data = file_get_contents("http://localhost/codeigniter/index.php/form/");
$html_encoded = htmlentities($data);
echo $html_encoded;
?>
在上面的代码中,我们在 $data
变量中获取了 url 的所有内容,然后在其中使用 htmlentities for html 编码...
我在
中有我网站的索引文件localhost-->mywebsite-->index.php
(这是我的外部脚本)
我已经用 codeigniter 建立了一个注册表。
我可以使用注册表单 url http://localhost/codeigniter/index.php/form。
但是我怎样才能将该注册表附加到我的网站索引文件中。
在我的外部 php 脚本(我网站的index.php
)中使用 include_once"../codeigniter/index.php/form";
无效。
但是,如果我将 'form'
作为默认控制器文件并使用来自外部 php 脚本的以下代码
include_once "codeigniter/index.php";
效果很好。但是如果我需要其他控制器文件而不仅仅是 'form'
怎么办?
更新:
我还可以从外部 php 脚本 link 到该文件,如下所示:
<a href="codeigniter/index.php/form>Register</a>.
但不包括。每当我包括它显示没有这样的文件。
在 localhost-->mywebsite-->index.php,你可以试试这个:
<?php include_once('/codeigniter/index.php/form'); ?>
如果没有,您可以将您的 index.php 代码移动到 codeigniter 视图中并以这种方式进行设置。
因此,如果我理解正确的话,您想在其他 php 网站上使用 codeigniter's
表单,实际上这样做的想法是 错误的 (因为你通常无法控制你的表单操作 link 等更好地直接在其他网站上构建相同的),但你的问题的答案是遵循技巧
将此代码放在您希望包含 codeigniter 表单的其他网站中
$output = shell_exec('php ABSOLUTE_PATH/codeigniter/index.php form index');
// where "ABSOLUTE_PATH" is absolute path to your codeigniter project
// "form" is your controller name
// "index" action name
echo $output; // will echo form html generated by codeigniter
尝试使用下面的代码...
<?php $data = file_get_contents("http://localhost/codeigniter/index.php/form/");
$html_encoded = htmlentities($data);
echo $html_encoded;
?>
在上面的代码中,我们在 $data
变量中获取了 url 的所有内容,然后在其中使用 htmlentities for html 编码...