Welcome Guest, Not a member yet? Register   Sign In
Invoking CodeIgniter from outside of CI (or on non-CI based sites), loading views
#1

[eluser]besson3c[/eluser]
Hello,

I wish to pull in all of the CodeIgniter functions from outside of CI for two reasons:

- allows me to write shared CI-based libraries/views in non CodeIgniter sites

- allows me to make AJAX calls to files not being redirected to CodeIgniter via mod_rewrite, and to speak in CodeIgniterese within these libraries.


So far, I have accomplished this via the following:

Code:
<?php
// For sites not using CodeIgniter, init CodeIgniter
require_once '/usr/local/www/mycisite/index.php';
    
$CI =& get_instance();    
    
// init site via centralized CodeIgniter site controller
$CI->_initsite();
?>

the "mycisite" CI site has all of my shared libraries and stuff that I need available outside of CI. This actually works fine.

My problem is, I cannot load views from the mycisite centralized CI site this way. Tracing this, I can see that with logging enabled and outputting the contents of the output buffer within system/libraries/Loader.php that it is not picking up the contents of the view for some reason. It just seems pretty confused about being invoked this way, and I haven't really pinpointed why and how.

As a work-around, I can simply simulate the load->view functionality by running an extract of my data object, and doing an old-fashioned include. However, for whatever reason running an include creates extra spaces in between tags which messes up some of my views. My workaround:

Code:
<?php
ob_start();
include '/usr/local/www/mycisite/system/application/views/myview.php';
$output = preg_replace('/>\s+</', '><', ob_get_contents());
ob_end_clean();
print $output;
?&gt;

All of this works too, but this is a little ugly and terribly confusing. My questions:

1) Is there a way to run a $this->load->view on a CodeIgniter site initialized by a PHP script including the site's index.php file? (i.e. on a non-CI site hacked to load all of the CI internals as per my first block of code, above)

2) Why does running an include statement from within a view produce extra whitespace?



I know that this is pretty odd. Believe me, I've spent a considerable amount of time mulling over a better way to go about this. My setup is pretty complicated, I have backwards compatibility with non-CI sites to contend with, which introduces a fair amount of complexity. For the sake of helping me, try to humor me that I have a reason for going about this this way Smile




Theme © iAndrew 2016 - Forum software by © MyBB