Welcome Guest, Not a member yet? Register   Sign In
Call Model Methods inside Controllers
#1

[eluser]JREAM[/eluser]
If I have a Controller called "Test" like below,
and I want to grab methods out of "Test_Model", how do I do this?
Code:
<?php

class Test extends Controller {

    function __construct()
    {
        parent::__construct();
    }
    
    function index()
    {
        $this->load->model('test_model');
        $this->load->view('test');
    }
}

Then how would you use that method?
Code:
$this->model->test_model->write();



I would also like to send variables to the View, and Im assuming its done with this:
Code:
$this->load->library('parser');  
$data['item'] = 'Test Text';
$this->parser->parse('test', $data);

Okay, so if I have a parser like that, do I get rid of this?
Code:
$this->load->view('test');
#2

[eluser]Colin Williams[/eluser]
Re-read over http://ellislab.com/codeigniter/user-gui...odels.html
#3

[eluser]Sean Gates[/eluser]
The model can be called like:

Code:
$this->test_model->write();

For your next question, I don't know why are you using a parser. For BBCode, Special characters or HTML conversion?

And, you should always use a view:

Code:
$data['item'] = 'Test Text';
$this->load->view('test', $data);

-- Sean
#4

[eluser]JREAM[/eluser]
Thanks for the fast replies. Okay I like how the model is called that way, AWESOME.

I thought you used the parser if you wanted to pass variables into the View lol Tongue
I also thought to use the shorthand style {$item} rather than <?php echo $item;?> you needed to use parser.

Ill re-read this model area I usually skim it over to figure out what Im doing then if it's not too frustrating I keep going!




Theme © iAndrew 2016 - Forum software by © MyBB