Little question about output - 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: Little question about output (/showthread.php?tid=1762) |
Little question about output - El Forum - 06-25-2007 [eluser]VivaUkraine[/eluser] In my controller i've code for retriving news from database : Code: $content = $this->db->get('news'); and i view i've a code like this. Code: <?foreach ($content->result() as $row):?> The problem is that i want to do some replacements in $row->content variable. For ex. i want to replace all '<code>' with '<code>' and all '</code>' with '</code>' tags. I dont want to do this in view file.... How can i do it in Controller ? Little question about output - El Forum - 06-25-2007 [eluser]ztinger[/eluser] in your controller Code: foreach ($content->result() as $row){ Little question about output - El Forum - 06-26-2007 [eluser]VivaUkraine[/eluser] [quote author="ztinger" date="1182820605"]in your controller Code: foreach ($content->result() as $row){ these replacements can be see only in controller; but in view file there is no replacements yet Little question about output - El Forum - 06-26-2007 [eluser]ztinger[/eluser] well , they should be. Be sure you are defining $data['content'] after you have done your replacements. Little question about output - El Forum - 06-26-2007 [eluser]VivaUkraine[/eluser] [quote author="ztinger" date="1182887993"]well , they should be. Be sure you are defining $data['content'] after you have done your replacements.[/quote] i've this code : Code: foreach($content->result() as $row) { but in view file i have old output, before replaces... Little question about output - El Forum - 06-26-2007 [eluser]marcoss[/eluser] I think you are not getting this right, this is what you should do. Code: // controller Now if you have records an array with them will be returned, else you will get an string with error message. So your view should look like this. Code: // view Little question about output - El Forum - 08-08-2007 [eluser]Unknown[/eluser] Hi, I'm new to CI and a PHP beginner but would really like that code example to work in my project. I'm trying to do a str_replace and the error is pointing to that command. I'm thinking that I would have to convert the object to an array first. Any help is appreciated. Code: Error Message: Undefined property: stdClass::$content Controller: Code: function index() View: Code: <?php if (is_array($content)) : foreach ($content as $row) : ?> Little question about output - El Forum - 08-08-2007 [eluser]Phil Sturgeon[/eluser] Code: else : Code: foreach ($content as $row) That's gonna end in tears... Little question about output - El Forum - 08-08-2007 [eluser]Derek Allard[/eluser] Just a quick look, but I think you need Code: $content[] = $row->content; in place of Code: $content[] = $row; Now... more importantly. Welcome to CI! |