Welcome Guest, Not a member yet? Register   Sign In
newbie question, passing data in and out of models
#1

[eluser]TornUp[/eluser]
I think this is going to be a simple and frequently asked question! i have searched the forum a little, but can't seem to find an answer that gives me enough infomation to get my head around this issue..

Im puzzled on how i would pass data in and out of a model..

for example, i currently have a simple registration page, with 3 inputs "email", "password1" and "password2"

when the user hits SUBMIT, it is then passed into controller for processing;
password1 and password2 are both compaired to see if they match(it is done client side with Jquery, but checked again to be safe) and sit in wait of the next checks.

and then this is where my problems start! how do i pass my "email" POST data into my model so i can query the database and check if the e-mail already exists?(and im guessing the function will return true if it does exist, that im able to handle)

i know i am able to post the data directly to the model, but i don't beleve that is the right thing to-do, and over time, will become messy!

sorry if this has been posted before, as i said before, i did check, but was unable to find anything fully relivant!
#2

[eluser]pistolPete[/eluser]
These topics are covered in these video tutorials: http://codeigniter.com/tutorials/
I suggest having a look at these and the user guide.

Btw: I'd recommend using the Form Validation library:
Quote:CodeIgniter provides a comprehensive form validation and data prepping class that helps minimize the amount of code you'll write.
#3

[eluser]TornUp[/eluser]
[quote author="pistolPete" date="1235956903"]I suggest having a look at these and the user guide.[/quote]

Thanks for the quick reply, i have looked through the user guide, but wasn't able to find any infomation on passing data, or maybe i was, and am just blind! lol

i will review the video tutorials(although, i thought they accessed the database through the controller, and never touched the models?)

many thanks for providing the helper link aswell, i shall have a look at that now Smile
#4

[eluser]pistolPete[/eluser]
Quote: i thought they accessed the database through the controller
That's right, sorry.

Passing data to a model is just like calling a normal php function:
Code:
$this->load->model('some_model');
// pass data to the model function insert()
$this->some_model->insert($data);

If you want to return data from your model, it's done the same way as every other function:
Code:
// in some_model.php
function get_entries($some_params)
{
   // query the database
   ...
   // return the results
   return $results;
}

// in your controller
$this->load->model('some_model');
$entries = $this->some_model->get_entries($put_your_params_here);




Theme © iAndrew 2016 - Forum software by © MyBB