Welcome Guest, Not a member yet? Register   Sign In
Calling a function from inside a view
#11

[eluser]Omaplie[/eluser]
Hi,

I am sorry, I wasn't be at home this we, I'll try tonight.
Thank you a lot.
#12

[eluser]Omaplie[/eluser]
Hi,

awesome, it works !!

Thank you very much for your help.
I really like this forum.

Thank you.
#13

[eluser]Omaplie[/eluser]
Hi,

Thank you for all your help but I have an another question.

I have my view where I call the function in the helper but after
that I would like to make a foreach on what I got.

My view :

Code:
<?php recup_email(); ?>
<?php foreach $em as $e): ?>
   <?php echo $e; ?>
<?php endforeach; ?>


My helper :

Code:
<?php
    function recup_email()
    {
        $CI =& get_instance();
        $CI->load->model('unite_model');
        
        $data['em'] = $CI->unite_model->email_membre_model();        
    }
?>

I think I need to load the $data but usually I made this :

Code:
$layout_network['contenu'] = $CI->load->view('list_vote_friend', $data, TRUE);
$this->load->view('layout_network',$layout_network);

But I can't hereā€¦ Do you have a solution ?

Many thanks.
#14

[eluser]Omaplie[/eluser]
I thought to use a
Code:
<?php return $data ?>
but it didn't work
#15

[eluser]InsiteFX[/eluser]
You can do it like this:
Code:
<?php
    function recup_email()
    {
        $CI =& get_instance();
        $CI->load->model('unite_model');
        
        $data['em'] = $CI->unite_model->email_membre_model();

        // make $data global to views
        $CI->load->vars($data);
    }
?>

// views - being returned
$layout_network['contenu'] = $CI->load->view('list_vote_friend', '', TRUE);

// views normal - no need to pass $data to view!
$this->load->view('list_vote_friend');

You may need to play around with it a bit!

#16

[eluser]Omaplie[/eluser]
Hi,

Thank you for your help.
Maybe I didn't understand but you load the variable in the helper.

What I would like to do is to call a function in a view, the function executed,
get the foreach of this function, on the same page.

Doo you understand me ?

In the view :

Code:
// CALL THE FUNCTION
<?php recup_email(); ?>

// INFORMATIONS GOT, MAKING A LOOP
<?php foreach($em as $e): ?>
<?php echo $e->email_membre; ?>
<?php endforeach; ?>
#17

[eluser]InsiteFX[/eluser]
If you use the load->vars like I mentioned you should have access to $em
#18

[eluser]Omaplie[/eluser]
It's weird because it seem doesn't work.

My helper :
Code:
function recup_email()
    {
        $CI =& get_instance();
        $CI->load->model('unite_model');
        
        $data['em'] = $CI->unite_model->email_membre_model();        
        
        $CI->load->vars($data);
    }

And my view :
Code:
<?php recup_email(); ?>
                                
<?php foreach($em as $e): ?>
<?php echo $e->email_membre; ?>
<?php endforeach; ?>

Thank you so much for your help.
#19

[eluser]CroNiX[/eluser]
load::vars() needs to be called BEFORE the view gets loaded, like from the controller. Surely you could just load that data properly from the controller instead of the view.
#20

[eluser]Omaplie[/eluser]
Do you suggest to make the foreach in the controller ?




Theme © iAndrew 2016 - Forum software by © MyBB