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

[eluser]CroNiX[/eluser]
No, code that has to do with displaying data should be in the view. Code dealing with retrieving data should be in the controller.
Code:
//Helper
function recup_email()
{
    $CI =& get_instance();
    $CI->load->model('unite_model');
        
    return $CI->unite_model->email_membre_model();  //just return it and load vars in the controller      
}
Code:
//Controller
$data['em'] = recup_email();
$this->load->vars($data);
//...
$this->load->view('your_view');
Code:
//View
<?php foreach($em as $e): ?>
<?php echo $e->email_membre; ?>
<?php endforeach; ?>
#22

[eluser]CroNiX[/eluser]
Also, do you mean "recoup" ? Smile
#23

[eluser]Omaplie[/eluser]
Hi thank you a lot for your help.

It's a really good idea but in your example, I don't understand how you call the controller.

Thank you a lot.
#24

[eluser]Omaplie[/eluser]
Yes, I mean « recoup », sorry Smile
#25

[eluser]Omaplie[/eluser]
Is it a way to recoup data without loading a view ?
#26

[eluser]ojcarga[/eluser]
Quote:
Code:
function recup_email()
    {
        $CI =& get_instance();
        $CI->load->model('unite_model');
        
        //#####
        return $CI->unite_model->email_membre_model();        
        //#####
        
    }

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

Take a look the code that is surrounded by "//#####" and try that.
#27

[eluser]Omaplie[/eluser]
Thank you so much !! It's exactly what I want. Thanks !




Theme © iAndrew 2016 - Forum software by © MyBB