Welcome Guest, Not a member yet? Register   Sign In
Cant understand How MVC works in CodeIgniter...
#2

[eluser]pickupman[/eluser]
Welcome to CI and the forums!

MVC is a common place for a lot of various programming languages. It is a practice of separating: accessing information from a database ([M]odel), what is seen in the browser ([V]iew), and how the logic of those two get are put together ([C]ontroller).

Take a look at the user guide about [url="http://ellislab.com/codeigniter/user-guide/overview/appflow.html"]Application Flow[/url] is good visual diagram. One of the strengths, and weakness some argue about CI, is that it doesn't force you to use strict MVC design. Your controller could have database calls, and html echoed. Your views could access the database, and do some logic.

For something you are designing, I don't think a model is quite necessary. Maybe I am just lazy, but if I only need to add something to the db, I may just do it in the controller. You will want to use the [url="http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html"]form validation library[/url] to check the input of your forms. You would end up with something like
Code:
$this->form_validation->set_rules('firstname', 'first name', 'trim|required|min_length[2]');
$this->form_validation->set_rules('lastname', 'last name', 'trim|required|min_length[2]');
$this->form_validation->set_rules('email', 'email address', 'trim|required|valid_email');

if($this->form_validation->run()){
  //Process form input into DB here
}

//Call view to display to the user
$this->load->view('your_view_form');

With those three simple lines along with the other information about form validation, you can make sure that all 3 fields are required, trim whitespace off, make sure the name fields have at least 2 characters, and a valid email address is given.


Messages In This Thread
Cant understand How MVC works in CodeIgniter... - by El Forum - 04-07-2011, 06:40 AM
Cant understand How MVC works in CodeIgniter... - by El Forum - 04-07-2011, 07:04 AM
Cant understand How MVC works in CodeIgniter... - by El Forum - 04-07-2011, 09:43 AM
Cant understand How MVC works in CodeIgniter... - by El Forum - 04-07-2011, 10:06 AM



Theme © iAndrew 2016 - Forum software by © MyBB