Welcome Guest, Not a member yet? Register   Sign In
TRUE contoller CRUD? Another way to not repeat myself?
#14

[eluser]umefarooq[/eluser]
Hi thanks, you have to write some code what ever, if you can see form generation library, it self you have learn it how its working another learning process, and its add some unnecessary html code also which you don't need, earlier i was also facing these kind to problem form and validation code to write again and again above code is reducing some of your work, to make it more common you can put reusable code in one library which can be access for every controller, example

Code:
// set rules code put in  library let see util
foreach($this->cols as $key => $v){
      $this->form_validation->set_rules($key,$key,$v['rule']);
     }

class util{

public $ci;

function util(){
   $this->ci = & get_instance();
}
  
  set_rules($cols){
       foreach($cols as $key => v){
           $this->ci->form_validation->set_ruels($key,$key,$v['rule'])
    }
}
create_form(){}
}

another thing if you are using any IDE like Netbeans giving good feature of code template or you class file template example here is one admin controller Netbeans template if you module name is like your controller you can call it also

Code:
class ${name}_admin extends Admin_Controller {
    //put your code here
    function ${name}_admin(){
        parent::Admin_Controller();
        $this->load->module('${name}_m');
    }

        function _remap($task){
        switch ($task){
            case 'edit':
            case 'add':
                $this->form();
            break;
            case 'publish':
                $this->publish();
            break;
            case 'delete':
                $this->delete();
            break;
            default:
               $this->view();
            break;
        }

    }



    function form(){

    }

    function view(){

    }

    function save(){

        redirect('admin/${name}');
    }

    function publish($publish=0){

        redirect('admin/${name}');
    }

    function delete(){

        redirect('admin/${name}');
    }


Messages In This Thread
TRUE contoller CRUD? Another way to not repeat myself? - by El Forum - 03-15-2010, 11:08 PM
TRUE contoller CRUD? Another way to not repeat myself? - by El Forum - 03-15-2010, 11:58 PM
TRUE contoller CRUD? Another way to not repeat myself? - by El Forum - 03-16-2010, 02:54 AM
TRUE contoller CRUD? Another way to not repeat myself? - by El Forum - 03-16-2010, 07:26 PM
TRUE contoller CRUD? Another way to not repeat myself? - by El Forum - 03-17-2010, 12:06 AM
TRUE contoller CRUD? Another way to not repeat myself? - by El Forum - 03-17-2010, 02:11 AM
TRUE contoller CRUD? Another way to not repeat myself? - by El Forum - 03-17-2010, 04:02 AM
TRUE contoller CRUD? Another way to not repeat myself? - by El Forum - 03-17-2010, 04:06 AM
TRUE contoller CRUD? Another way to not repeat myself? - by El Forum - 03-17-2010, 10:23 AM
TRUE contoller CRUD? Another way to not repeat myself? - by El Forum - 03-17-2010, 10:31 AM
TRUE contoller CRUD? Another way to not repeat myself? - by El Forum - 03-17-2010, 10:45 AM
TRUE contoller CRUD? Another way to not repeat myself? - by El Forum - 03-17-2010, 10:49 AM
TRUE contoller CRUD? Another way to not repeat myself? - by El Forum - 03-17-2010, 10:58 AM
TRUE contoller CRUD? Another way to not repeat myself? - by El Forum - 03-17-2010, 11:52 PM
TRUE contoller CRUD? Another way to not repeat myself? - by El Forum - 03-18-2010, 12:26 AM
TRUE contoller CRUD? Another way to not repeat myself? - by El Forum - 03-18-2010, 01:41 AM



Theme © iAndrew 2016 - Forum software by © MyBB