Welcome Guest, Not a member yet? Register   Sign In
Generate content using views as template
#1

[eluser]Unknown[/eluser]
Hello,

I know that this post might sound stupid and I also know that it is possible to solve this issue using other method that not involves views, but I am still curious.

So, let get to business.

I created a helper function that generates the HTML for showing a message. The function in the helper is:

Code:
function msgbox($msg = NULL, $id_tag = NULL)

{

    $CI =& get_instance();

    

    $data['msg'] = ($msg === NULL ? '' : $msg);



    if ($id_tag !== NULL)

    {

        $data['msg_id_tag'] = $id_tag;

    }

    

    return $CI->load->view('widgets/msgbox', $data, TRUE);

}

When I want to generate a message box I call in the view <?php echo msgbox('Some message!', '#some_id'); ?>

The problem is when I call the function again, with no $id_tag specified like msgbox('Some other message!'); because the first $id_tag value remains set in the view.

What can I do, to prevent the first $id_tag not to propagate to the second message box too.

Thanks!
#2

[eluser]jedd[/eluser]
Can't you just call it the second time using NULL as the 2nd parameter?
#3

[eluser]Unknown[/eluser]
So you say to send $data['msg_id_tag'] as '' and check in the view what to display!?!

I guess this is the answer. I am an idiot!!! Smile
#4

[eluser]TheFuzzy0ne[/eluser]
I'm not sure if that will work. At the very worst, you might have to override the msg_id_tag variable to something else.




Theme © iAndrew 2016 - Forum software by © MyBB