what is worng with this foreach and for loops

#1
[eluser]BaRzO[/eluser]
Hi all,

I am having a problem with my code.
My controller.
Code:
<?php

class Welcome extends Controller {

    var $settings;

    function Welcome() {
        parent::Controller();
        $this->load->database();
        $this->load->library('theme_lib');
        $this->load->helper('url');
    }

    function index() {
        $this->theme_lib->_add_js("/* js comment */"); // this works
        for ($i=0; $i<=5; $i++) {
           $this->theme_lib->_add_js("/* js comment */"); // does not work
        }
    }
}

and my theme_lib
Code:
&lt;?php

class Theme_lib {

    var $CI;
    var $_embed_js = '';

    function Theme_lib() {
        $this->CI = & get_instance();

        log_message('debug', __CLASS__ . " Class Initialized");
    }
    function _add_js($js, $type = 'embed') {
        if ($type == 'embed') {
            $this->_embed_js .= $js . "\n";
        } else {
            $this->_js[] = $js;
        }
    }
}

Why this _add_js function does not work in for or foreach loops ?
Pls Help...
Thnks.

#2
[eluser]cahva[/eluser]
Seems to work fine.
Code:
function index()
    {
        $this->load->library('theme_lib');
        $this->theme_lib->_add_js("/* js comment */"); // this works
        for ($i=0; $i<=5; $i++) {
           $this->theme_lib->_add_js("/* js comment */"); // does not work
        }

        echo $this->theme_lib->_embed_js;
    }
..prints 7x "/* js comment */"

#3
[eluser]BaRzO[/eluser]
Yes i did test it the code. It's works but in my app there is something goes wrong.
I am still looking all code but i did find it yet.
Thnks


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.