![]() |
how do I include() files within a view? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: how do I include() files within a view? (/showthread.php?tid=19707) |
how do I include() files within a view? - El Forum - 06-16-2009 [eluser]Ascenti0n[/eluser] Hi all What I'm trying to do is have html files included within a section of a view file for certain content types/categories. So say with the controller I have retrieved the files' path from the database, and then call the view - eg: Code: $data[$file-path] = "topcs/"; and in the view, I would like to do something like: Code: <!-- As you may have guessed, this didn't work. Can someone please explain what I need to do. Thanks how do I include() files within a view? - El Forum - 06-16-2009 [eluser]TheFuzzy0ne[/eluser] Please could you be more specific than "this didn't work"? I can see several errors with your code above: 1) I think this is a typo: $data[$file-path] = "topcs/"; Should be $data['file_path'] = "topics/"; 2) You can't use hyphens in variable names, since they are interpreted as arithmetic operators, and what follows will be read as being a string. I'm sure you'd get a parse error with the code you have. how do I include() files within a view? - El Forum - 06-16-2009 [eluser]Ascenti0n[/eluser] Sorry for vagueness. In the interest of keeping this simple and to illustrate better the problem I am facing, I added the following to my view, in place of the previous code: Quote:<?php include(base_url() . 'welcome-home.php'); ?> and I see this in my browser: Quote:Severity: Warning any ideas? how do I include() files within a view? - El Forum - 06-16-2009 [eluser]TheFuzzy0ne[/eluser] It's because you're trying to include a file from a remote location (or rather via the HTTP protocol), and your server has the furl_open directive disabled. Your base URL starts with http://, which is a URL, but the file path you try to include would probably be better off like this: Code: include(APPPATH.'path/to/file'.EXT); # Assuming the file is within your application directory. how do I include() files within a view? - El Forum - 06-16-2009 [eluser]jedd[/eluser] I'd probably pull this in to the controller. Code: $data[$static_bit] = file ($filename); // How you establish $filename is up to you view: Code: echo $static_bit; Establishing $filename, as you've discovered, is non-obvious because you are trying to keep your code repository (within CI) fairly portable. You should rely on the url_base (and similar) rather than go absolute references. You might be able to stick this in your ./assets/static_pages/ directory and still pull it out with the CI functions .. but haven't tried, so can't say for sure. how do I include() files within a view? - El Forum - 06-16-2009 [eluser]jedd[/eluser] Oh, just read ... sorry, should have done this first. [url="http://ellislab.com/codeigniter/user-guide/helpers/file_helper.html"]CI User Guide - for File Helper[/url]: Quote:read_file('path') how do I include() files within a view? - El Forum - 06-16-2009 [eluser]Ascenti0n[/eluser] Thank you all very much. I will give all of those suggestions a go. I suppose it would be easier to pull the content from the database, but I just don't want to do that. |