CodeIgniter Forums
why in my Model cant use $this->load->view() ?? - 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: why in my Model cant use $this->load->view() ?? (/showthread.php?tid=21601)



why in my Model cant use $this->load->view() ?? - El Forum - 08-15-2009

[eluser]yudahebat[/eluser]
why in my Model cant use
Code:
$this->load->view('signup');
only can use
Code:
redirect('mrputucar/signup');

is it because I call from controller use
Code:
this->load->view('model_name',$data)
so it wouldn't work ??


why in my Model cant use $this->load->view() ?? - El Forum - 08-15-2009

[eluser]pistolPete[/eluser]
Views are loaded in the controller, that's how MVC is supposed to work.

Please read the user guide about MVC:
http://ellislab.com/codeigniter/user-guide/overview/mvc.html
http://ellislab.com/codeigniter/user-guide/overview/appflow.html


why in my Model cant use $this->load->view() ?? - El Forum - 08-15-2009

[eluser]verynewtothis[/eluser]
Models aren't made to do this... It's the controller's job to move requests among the 3 layers of MVC... If you ask me, I would say even the redirection code shouldn't be written in the models and should be done through controllers..


why in my Model cant use $this->load->view() ?? - El Forum - 08-15-2009

[eluser]meridimus[/eluser]
The controller is the place that calls database operations from your models and gives parsed data to your views.

Basically, what you're doing is cute, but it's wrong.


why in my Model cant use $this->load->view() ?? - El Forum - 08-15-2009

[eluser]InsiteFX[/eluser]
Hi,

In the old day's it was like this:

Input
Proccessing
Output

To take this a step forward to MVC:

Input Controller
Processing Model
Output View

Hope that helps.

Enjoy
InsiteFX


why in my Model cant use $this->load->view() ?? - El Forum - 08-16-2009

[eluser]yudahebat[/eluser]
my problem actually want to set_value on form signup

but because I use redirect on model it can display on the redirect page.

this is my view(only the form) :
Code:
$attributes = array('class' => 'cssform', 'id' => 'myform');
                    echo form_open('/mrputucar/create_member/', $attributes);
                    echo '<div id="error2">';
                    echo $this->session->flashdata('error_sign');
                    echo $this->session->flashdata('success_text');
                    echo '</div>';    
                    echo form_hidden('id','');
                    echo form_hidden('level','mbr');
                    echo '<p>';
                    echo form_label('Username', 'username');
                    echo form_input('username',set_value('username')); echo '&nbsp;*)';
                    echo '</p>';
                    echo '<p>';
                    echo form_label('Password', 'password');
                    echo form_input('password',set_value('password'));echo '&nbsp;*)';
                    echo '</p>';
echo '<div style="margin-left: 160px;">';
                        $data = array(
                        'id'   => 'submitbutton1',
                        'value'=> 'Create',
                        );
                        echo form_submit($data);
                        $data = array(
                        'id'   => 'submitbutton1',
                        'value'=> 'Reset',
                        );
                        echo form_reset($data);
                        echo '</div>';
                    
                    echo form_close();

this is my controller:
Code:
function signup()
    {
        $data['css']         = $this->css;
        $data['base']         = $this->base;
        $data['menu_web']     = $this->menu;
        $data['myrobots']     = '&lt;meta name="robots" content="noindex,nofollow"&gt;';
        $data['mywebtitle'] = 'mrputucar | Sign Up';
    
        $this->load->view('signup',$data);    
    }    

....

function create_member()
    {
        $data = $this->Crud->create_member();
        $this->load->view('crud', $data);    
    }

and my model :
Code:
(validation rules)
....
if ($this->validation->run() == false)
        {
        
            $flashdata = array('error' => true, 'error_sign' => $this->validation->error_string);
            $this->session->set_flashdata($flashdata);
        
            redirect('/mrputucar/signup/');    
} else { ...

do you have any idea to set_value if you see my code??


why in my Model cant use $this->load->view() ?? - El Forum - 08-16-2009

[eluser]InsiteFX[/eluser]
The code in your model should be in your view.

Enjoy
InsiteFX


why in my Model cant use $this->load->view() ?? - El Forum - 08-16-2009

[eluser]yudahebat[/eluser]
ohhh... yeah thats work. thnks friend...


why in my Model cant use $this->load->view() ?? - El Forum - 08-16-2009

[eluser]InsiteFX[/eluser]
Anytime

Enjoy
InsiteFX