Reputation: 2943
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
Upvotes: 0
Views: 2547
Reputation: 4984
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.
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
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.
Upvotes: 0
Reputation: 28752
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..
Upvotes: 2
Reputation: 57268
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
Upvotes: -1