Welcome Guest, Not a member yet? Register   Sign In
How does Model and Controller Variable Passes
#1

[eluser]JingCleoVil[/eluser]
How does model variable model passes back to controller?

i.e.
--Controller--
Code:
<?php
class Main extends Controller()
{
    function Main()
    {
      parent::Controller()
    }
    function index()
    {
       $data['result'] = from model variable
       $this->load->view('main/index',$data);
    }
    function insert()
    {
       $this->load->model('member');
       $this->model->insert();
    }
}
?>

--Model--
Code:
<?php
class Member extends Model
{
     var $name = '';
     var $email = '';
    
     function Member()
     {
        parent::Model();    
     }
     function insert()
     {
        $this->name = $_POST['name'];
        $this->email = $_POST['email];
        $this->db->insert('member',$this);
        $variable = 'must be pass to the $data['result']
     }
}
?>

I would like to use Model as my alternative way of validation instead of form_validation( i knew how does this work.).

Thanks in advance.
#2

[eluser]Colin Williams[/eluser]
Just so we know where you are coming from, what is your experience with PHP?
#3

[eluser]JingCleoVil[/eluser]
I am new here just a couple of months.and several months experience in PHP.

Kindly just ignore my sample code.i just want to know how to pass variable from model back to controller.
#4

[eluser]Colin Williams[/eluser]
Use 'return'

Code:
function get_colors()
{
   $result = array('red', 'green', 'blue');
   return $result;
}
#5

[eluser]JingCleoVil[/eluser]
@Colin Williams

Thank you for the prompt reply. Will try it.




Theme © iAndrew 2016 - Forum software by © MyBB