Welcome Guest, Not a member yet? Register   Sign In
Help with basic CRUD (create and edit) (with datamapper)
#1

[eluser]NachoF[/eluser]
How do you usually manage CRUD in your app?

The way I see it, there should be two methods for create and two for edit....one to simply display the form and the other one to actually create it after forms been submited... but php doesnt support overload of methods so they should be named differently... how do you usually handle this?? right now what I have is this but I would appreciate some tips on how to improve my method cause it just looks ugly.

Code:
function Create()
        {
            $u = new User();
            $g=new Group();
            $g->get();
            if($_POST)
            {
                $u->name=$this->input->post('nombre');
                $u->login=$this->input->post('login');
                //populate $u with all of the fields that come from the form
                
                if($u->save($g))
                                {
                                       //set flash data user created succesfully
                    redirect("index");
                                 }
                else
                {                
                    $this->template->build('users/create_view', $data);
                }
            }
            else
            {
                $this->template->build('users/create_view', $data);
            }            
        }




Theme © iAndrew 2016 - Forum software by © MyBB