load controller output into another view |
[eluser]Maks Baum[/eluser]
Hi i want to have sth like this: main_page - controller & view (not cached becouse of login form etc.) news - controller & view - output (not DB) cached load news into main_page - controller or directly view - doesn't really matter How Can i achieve that? Is it possible in clean CI? Use file_get_contents ? or sth simillar? file_get_contents with http ?
[eluser]gtech[/eluser]
1)cheat and use an iframe ![]() 2)create a div with an id in your view and use javascript to make a call to the news controller and return the content in the div. jquery is excelent for doing this [url="http://docs.jquery.com/Ajax/jQuery.ajax#options"](http://docs.jquery.com/Ajax/jQuery.ajax#options)[/url]. check out the example code. Code: <head>
[eluser]Maks Baum[/eluser]
yes I know I can use javascript ... but I don't want to ![]()
[eluser]nmweb[/eluser]
http://ellislab.com/forums/viewthread/80279/ Might be of some help to you or look for HMVC on the forums.
[eluser]gtech[/eluser]
ok use an iframe then ![]() if you want you could move the 'news controller' functionality to a library and then you can just call the library with in your main controller but I am not sure how that affects caching if I am honest. [edit] @nmweb.. didn't know that existed cheers
[eluser]Maks Baum[/eluser]
so... when I use clean CI ... think that file_get_contents will be the best method to have some part of the view to be cached and rest not to. Glad that somebody coded sth like curl_file_get_contents becouse my hosting provider has disabled getting external content via file_get_contents and http ![]() HMVC... maybe with next site ![]()
[eluser]nmweb[/eluser]
Using file_get_contents in the way you describe is not something I would recommend. It's another http request where it is not necessary. Using output buffering and the Wick library I linked to you should be able to achieve it in a neater and faster way.
[eluser]Maks Baum[/eluser]
First: Ok mweb this HMVC from Your post is quite simple and good... but I need to get the 'output' into lets say a string and then use it in another controller - the main controller from which other is called via HMVS, anyone know how to do that? Should I just overwrite _output() and put $output into eg $_REQUEST['some_variable_name']? And the second (solution): When using gtech method (with jquery || other ajax library, functions) remember to: header('Content-Type: text/html; charset=iso-8859-2'); //optional, but I have to becouse site is in this encoding and default everything goes utf header("Cache-Control: no-cache"); // 'a must have' this or/and this one under for IE becouse it cached me the output and every time i saw the login box instead of logged user menu ![]() header("Pragma: no-cache");
[eluser]wiredesignz[/eluser]
Check out Modular Extensions on the forums and wiki. (see my signature) It will certainly do what you descibe.
[eluser]oddman[/eluser]
The modular extensions is something that is sorely needed as part of the core codeigniter framework. CakePHP uses what's known as components - and it's built for exactly this kind of thing. |
Welcome Guest, Not a member yet? Register Sign In |