将 codeigniter 页面包含到非 codeigniter php 页面中

发布于 2024-10-10 04:45:45 字数 702 浏览 0 评论 0原文

我正在开发一个 CMS,它不是自动生成页面,而是生成代码并将其提供给用户以添加到他们的 php 页面。

我正在将应用程序转移到 CI,但正在努力解决如何设置此流程。

通过制作 2 个 codeigniter 索引页(一个用于主应用程序,另一个用于连接,这会更改初始控制器和索引路径),这几乎可以工作,我想要的是这样的:

<?php include("cms/connector.php"); ?>
<html>
..
<body>
<h1>Static</h1>
<?php echo($cms['data']); ?>
</body>

它正确地提取文件并运行视图被调用,但视图中的变量不会被保存。

另外,我需要能够定位他们试图获取的 cms 页面,但是:

<?php include("cms/connector.php/cms/2"); ?>

不再有效(我猜是因为没有扩展名?)如果我能让这部分工作,我就不需要担心变量,因为我可以直接在页面上包含视图

任何想法都很棒

应用程序可以托管在各种设置上,因此如果我可以绕过包含直接 url (http) 的需要,我会希望它,因为它可能并不总是被打开默认开启。另外,我不想使用 ajax 来拉取,因为我希望搜索引擎能够很好地获取内容

I am working on a CMS that instead of generates pages automatically, it generates code and gives it to the user to add to their php page.

I am in the process of moving the application to CI but struggling with how to set up this process.

By making 2 codeigniter index pages (one for the main application and the other for connecting which changes the initial controller and index path) this almost works, what I would desire would be something like this:

<?php include("cms/connector.php"); ?>
<html>
..
<body>
<h1>Static</h1>
<?php echo($cms['data']); ?>
</body>

It pulls the file correctly and runs the view that is called, but the variables from the view are not saved.

Also I need the ability to target the cms page they are trying to get, however:

<?php include("cms/connector.php/cms/2"); ?>

No longer works (I guess because there is no extension?) If I could get this part to work I wouldn't need to worry about the variables since I could just include the view directly on the page

Any ideas would be great

The application could be hosted on various setups, so I would like it if I could bypass the need to include the direct url (http) since it might not always be turned on by default. Also I don't want to pull with ajax since I want the content to be picked up well by search engines

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

寒冷纷飞旳雪 2024-10-17 04:45:45

您可以使用 PHP 的 cURL 模块。以下摘自文档中的示例。

<?php
// create a new cURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/cms/connector.php/cms/2");
curl_setopt($ch, CURLOPT_HEADER, 0);

// grab URL and pass it to the browser
curl_exec($ch);

// close cURL resource, and free up system resources
curl_close($ch);
?>

请注意,这将拉取整个文档,包括 doctype、 等。如果您将其包含在另一个页面中,这不是您想要的。您可能想修改connector.php以仅输出文档的正文。

You can use PHP's cURL module. Below is taken from the examples in the documentation.

<?php
// create a new cURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/cms/connector.php/cms/2");
curl_setopt($ch, CURLOPT_HEADER, 0);

// grab URL and pass it to the browser
curl_exec($ch);

// close cURL resource, and free up system resources
curl_close($ch);
?>

Note that this will pull the ENTIRE document, including doctype, <head>, etc. This is not what you want if you're including this in another page. You probably want to modify connector.php to output only the body of the document..

别挽留 2024-10-17 04:45:45

听起来你正在设计一个 api。

(我不确定为什么你一半使用 CI,剩下一半使用自定义脚本。CI 可以满足你的需求。)

以下建议可能是显而易见或超出您的预期答案,但万一它有帮助,我想把它放在桌面上。

如果我正确理解您的问题和评论,那么您的用户在您的服务器上拥有网站。您还有一个应用程序,为他们提供代码,他们将这些代码粘贴到其站点中,以某种方式处理您服务器上的信息。

  1. 您需要一个控制器来接收来自粘贴代码的信息请求
  2. 您需要一种方法来验证请求
  3. 用户提供某种变量信息
  4. 您需要根据用户提供的变量在成功验证后返回信息或 html。

Codeigniter 允许您使用基于分段的 url 或查询字符串。它更喜欢并在带有段的框中工作,但可以配置为使用查询字符串

您可以构造一个包含

  1. 控制器名称和处理请求的函数的 url(而不是您提到的
  2. 用于验证请求的令牌的第二个索引页面)。理想情况下,这将用于与令牌存储在数据库中的信息进行比较创建并发布给用户:http: //www.infoq.com/news/2010/01/rest-api-authentication-schemes 这也是: http://oauth.net/
  3. 用户提供的信息

示例:

"example.com/cms/(index.php)/connector/function-name/auth-token/user-info"

一旦你的控制器处理完请求,将信息返回给用户。

Sounds like you are designing an api.

(And I'm not sure why you are using CI for half of it and custom scripts for the rest. CI can accomodate your needs.)

The following suggestion might be obvious or outside of your expected answers, but on the off-chance it helps, I wanted to put it on the table.

If I understand your question and comments correctly, you have users who have sites on your server. You also have an application that gives them code that they paste into their site that somehow works with information on your server.

  1. You need a controller that receives requests for information from the pasted code
  2. You need a way to authenticate the request
  3. The user provides some kind of variable information
  4. You need to return information or html upon successful validation, based on variables provided by the user.

Codeigniter allows you to work with segment based url's or with query strings. It prefers and works out of the box with segments, but can be configured to work with query strings.

You may construct a url that contains

  1. the name of a controller and function to process the request (instead of the second index page you mentioned
  2. a token for authenticating the request. This would ideally be used to compare to information stored in the db when the token is created and issued to the user. Check out this article: http://www.infoq.com/news/2010/01/rest-api-authentication-schemes and this one too: http://oauth.net/
  3. information provided by the user

An example:

"example.com/cms/(index.php)/connector/function-name/auth-token/user-info"

Once your controller processes the request, return the information to the user.

回首观望 2024-10-17 04:45:45

Codeigniter 根据 URI 的环境状态路由应用程序

您需要做的是设置环境并包含索引视图文件,如下所示:

$_SERVER["REQUEST_URI"] = "cms/2";

//Set GET action,method params etc

require_once "path/to/index.php";

当您加载 CI 索引文件时,它会读取 SERVER 变量以及您可能必须找到的其他变量执行控制器和方法,我还建议您修改库/视图文件,因为它可能会在输出时退出,导致脚本退出。

您也可能希望查看 ob_start() 等来捕获缓冲区

Codeigniter routes the application depending on the environment state of the URI

What you need to do is set the environment and include the index view file like so:

$_SERVER["REQUEST_URI"] = "cms/2";

//Set GET action,method params etc

require_once "path/to/index.php";

When you load CI Index file it reads the SERVER Variable and others which you may have to find and execute the controller and method, i would also advise that you modify the library/view file as it may exit upon output causing your script to exit.

Also you may wis hto look into ob_start() etc to catch the buffer

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文