Welcome Guest, Not a member yet? Register   Sign In
Model Example is Bad in User Guide
#1

[eluser]Unknown[/eluser]
I Am very new to Code Igniter however I have been taught MVC before, I have been reading through the user guide and let me first say how impressive the documentation is. However I have a real disagreement with the example used on page:

http://ellislab.com/codeigniter/user-gui...odels.html

The example extends the running Blog example which is fine however the following function is concerning:

Code:
function insert_entry()
    {
        $this->title   = $_POST['title']; // please read the below note
        $this->content = $_POST['content'];
        $this->date    = time();

        $this->db->insert('entries', $this);
    }

I believe that the reference to the POST variables whether through $this->input->post or $_POST violates the fundamental ideal of Model in MVC. The model by its very nature should be abstracted from the fact that this is even a web implementation let alone be directly referencing POST variables. This function should take "title" and "content" as parameters so that it may be called from anywhere in the program even if it was not directly related to a POST request.

From my understanding of MVC each layer should be isolated from each other sharing only an interface. This type of function removes any and all benefits of MVC, and is a particularly bad example to show as an introduction to Model. The interface between Model and Controller should pass ALL necessary information across so regardless of what changes as long as that interface is adhered to you do not need to recode anything else.

For example: If I now call that function like so

Code:
$this->Blog_Model->insert_entry()

1) It is not clear what this is going to insert.
2) If this is called from a place where the POST values are not available or not related to what you wish to insert. Your function no longer works.

I believe that this needs correction because it is the first introduction to models given to newcomers.

Regards Boblemur


Messages In This Thread
Model Example is Bad in User Guide - by El Forum - 07-27-2010, 09:13 PM
Model Example is Bad in User Guide - by El Forum - 11-18-2010, 07:37 PM
Model Example is Bad in User Guide - by El Forum - 11-22-2010, 11:38 PM
Model Example is Bad in User Guide - by El Forum - 02-07-2011, 03:44 PM
Model Example is Bad in User Guide - by El Forum - 02-07-2011, 07:48 PM
Model Example is Bad in User Guide - by El Forum - 02-07-2011, 07:55 PM
Model Example is Bad in User Guide - by El Forum - 02-07-2011, 08:38 PM
Model Example is Bad in User Guide - by El Forum - 02-07-2011, 08:52 PM
Model Example is Bad in User Guide - by El Forum - 02-07-2011, 09:10 PM
Model Example is Bad in User Guide - by El Forum - 02-07-2011, 10:10 PM
Model Example is Bad in User Guide - by El Forum - 03-29-2011, 01:37 AM
Model Example is Bad in User Guide - by El Forum - 03-29-2011, 04:41 PM
Model Example is Bad in User Guide - by El Forum - 03-29-2011, 07:40 PM
Model Example is Bad in User Guide - by El Forum - 03-29-2011, 10:16 PM
Model Example is Bad in User Guide - by El Forum - 03-30-2011, 03:02 AM
Model Example is Bad in User Guide - by El Forum - 03-30-2011, 07:01 AM
Model Example is Bad in User Guide - by El Forum - 03-30-2011, 07:16 AM
Model Example is Bad in User Guide - by El Forum - 03-30-2011, 10:44 AM



Theme © iAndrew 2016 - Forum software by © MyBB