[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}');
}