[eluser]Chris Papaioannou[/eluser]
Hey guys
Building a website at the moment in CI which I'm relatively new to. The website has a menu which goes across all pages, this is formed up using the following snippets of code (will only put whats relevant).
In the constructor of every controller
Code:
$this->data['menu'] = $this->load->view('menu', array('menu' => $this->Menu_model->get_menu()), TRUE);
Followed by this in the actual page functions
Code:
$data = $this->data;
$this->load->view('layout', $data);
The Menu_model->get_menu() just returns an array of data to the 'menu' view.
This setup works fine on the website itself, though I'm sure it could be done better/more efficiently its not my main concern at the moment.
There is a forum which runs alongside the website (Invision Power Board) and I want to include this menu on there too. My current though is that this is going to be a bit tricky, due to the need for a controller, model and view to all be used in someway to help generate the menu output. I've created a controller dedicated to outputting the menu only which contains the following code
Code:
<?php
class Menu extends CI_Controller {
function __construct(){
parent::__construct();
// Load configs
$this->config->load('general');
// Forum integration
require_once($this->config->item('IPBWI','includes'));
$this->ipbwi = clone $ipbwi;
if($this->ipbwi->member->isLoggedIn()){
$this->member = $this->ipbwi->member->photo(null,true,true);
$this->load->vars(array('member' => $this->member));
}
// Common models
$this->load->model('Menu_model');
}
function index() {
$this->load->view('menu', array('menu' => $this->Menu_model->get_menu()));
}
}
Viewing this at 'www.site.com/menu' works fine, but I'm stumped at how to get this output into an external PHP file. I'd have to include the CI index.php and pass it parameters to get the right controller showing.
Current solution is to put this in a standalone file 'menu_include.php'
Code:
<?
// create a new cURL resource
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://site/menu");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch,CURLOPT_COOKIE,$_SERVER['HTTP_COOKIE']);
// grab URL and pass it to the browser
curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);
?>
And then to go into the invision skinning and use the following line, because I believe its quite tricky to even get a php include working through IPB and you have to use their custom syntax.
Code:
{parse include="../menu_include.php"}
This all works fine, but I don't think I should have to be using curl to be able to grab the output of the menu controller as if I'm an external visitor. How on earth can I streamline this so its not such a clusterfuck of code. Have spent a fair time on google looking at various solutions but presume I'm describing the issue badly in my queries.
TL;DR. How can I include the complete output from a CI controller, into another non CI page through use of internal includes rather than external curl/file get contents style includes.
Thanks for any help!