![]() |
codeigniter is not parsing html from db for php tags...? - 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: codeigniter is not parsing html from db for php tags...? (/showthread.php?tid=14448) |
codeigniter is not parsing html from db for php tags...? - El Forum - 01-02-2009 [eluser]Colin McCubbin[/eluser] I'm new to codeIgniter and an struggling with this.. :-S If I put some php code in <?php...?> tags in amongst the html in a view file, codeigniter parses and acts on the php before sending the page to the browser with no problem. But if I put that same block of mixed html and php in a database field and then get codeigniter to get it from the db, place it in a variable and output it, the php is not parsed and just shows up as text.. EG. I load the html helper in my controller, and in my view.php file have Code: <?php echo img('system/application/pics/Aragon.jpg');?> If however I place the same line in my db field and get that and output it, it jus appear as a text string... So I get no image in the page, and if I 'view source' I see the php tags in the source.. What am I doing wrong here? Do I have to pass the db contents back into the php parser somehow? I'd have thought that codeigniter would have done that.. Thanks! codeigniter is not parsing html from db for php tags...? - El Forum - 01-02-2009 [eluser]Armchair Samurai[/eluser] If you fully intend to do it this way or have no other choice, you'll need to use eval(). This of it this way: at the moment, you're essentially doing this: Code: <?php echo "foobarfoobarfoobar <?php echo img('system/application/pics/Aragon.jpg');?> foobarfoo bar foobar";?> ... which, of course, will output that exact string. codeigniter is not parsing html from db for php tags...? - El Forum - 01-02-2009 [eluser]Colin Williams[/eluser] Doesn't sound like such a good idea. Don't just eval() it. You ought to put in some precautions. codeigniter is not parsing html from db for php tags...? - El Forum - 01-03-2009 [eluser]Colin McCubbin[/eluser] Thanks for the info.. I've realized that yes, ci is just outputting the contents of a variable, so doesn't do any parsing on it. And Colin, thanks , I'll check out the template library . I fixed my problem for now, the php code was just referencing images, and after trying various paths I found that if I moved my 'pics' folder to be a sibling to 'system', (ie under the site root) I just had to replace all refs in my database from code such as: Code: <?php echo img('system/application/pics/Aragon.jpg');?> to a straight html: Code: <img src="../pics/Aragon.jpg" /> I'm sure there is 'better way' to do this, but I'm learning oop and ci hand in hand and if everything worked first time I'd probably learn less! I had thought that paths would be relative to the file they were 'in', eg that pics would be referenced as a sibling of the view folder that contained the view, but it turned out that it had to be referenced to the original controlling index.php file (I guess??) codeigniter is not parsing html from db for php tags...? - El Forum - 01-03-2009 [eluser]Colin McCubbin[/eluser] Aaagh! Something is still wrong with my understanding of the paths involved. menu.php is my controller, and menu_view.php is the view, in their respective folders. 1. If I type Code: http://localhost/codeIgniter/index.php/menu But to set menu as my default controller, in routes.php I set Code: $route['default_controller'] = "menu"; 2. When I type Code: http://localhost/codeIgniter/ I've tried adding a duplicate 'pics' folder as a sibling to 'controllers' and 'views' but still no pictures. I'm currently at a loss to under stand the relationship 'pathwise' between html in view files and folders elsewhere on the site, especially as it seems to alter as described above. In the first instance where the picture displays, if I do view picture in my browser the url is as expected, namely Code: http://localhost/codeIgniter/pics/Aragon.jpg In the second, no picture, if I do view picture in my browser, the url is: Code: http://localhost/pics/Aragon.jpg Edit: Tried this and it works.. :lol: If anyone can take the time to explain why the paths changed to me I'd be very much in your debt! Thanks. |