Sunday 29 January 2017

abc

<?php
class abc extends CI_controller
{
function __construct()
{
parent::__construct();
$this->load->model('dbabc');

$login=$this->session->userdata('username');

if($login=='')
{
redirect('login');
}

}
function index()
{
$this->form_validation->set_rules('username','Name','required|alpha');
$this->form_validation->set_rules('password','Name','required');
$this->form_validation->set_rules('address','Name','required');
$this->form_validation->set_rules('contact','Name','required|is_numeric|min_length[10]|max_length[10]');
$this->form_validation->set_rules('email','Name','required|valid_email');
$this->form_validation->set_rules('gender','Name','required');
$this->form_validation->set_rules('city','Name','required');
$this->form_validation->set_rules('hobby','Name','required');

if($this->form_validation->run()==false)
{
 $this->load->view('form');
}
else
{
$abc['upload_path']='upload';
$abc['allowed_types']='png|jpg|jpeg|gif';
$this->load->library('upload',$abc);
if(!$this->upload->do_upload('image'))
{
$file="";
}
else
{
$file=$this->upload->file_name;
}

$abc=array('username'=>$_POST['username'],
'password'=>$_POST['password'],
'address'=>$_POST['address'],
'contact'=>$_POST['contact'],
'email'=>$_POST['email'],
'gender'=>$_POST['gender'],
'city'=>implode(',',$_POST['city']),
'hobby'=>implode(",",$_POST['hobby']),
'image'=>$file);
$this->dbabc->insertwww($abc);
redirect('abc/view');
}
}
function view()
{
$data['result']=$this->dbabc->getalldata();
$this->load->view('view',$data);
}
function search()
{
$data['result']=$this->dbabc->getsearch();
 $this->load->view('view',$data);
}
function delete($id)
{
$abc=$this->dbabc->deleteimg($id);
unlink("upload/".$abc->image);

$this->dbabc->delete($id);
redirect('abc/view');
}
function edit($a)
{
if($a=='')
{
redirect('abc/view');
}
$this->form_validation->set_rules('username','Name','required');
$this->form_validation->set_rules('password','Name','required');
$this->form_validation->set_rules('address','Name','required');
$this->form_validation->set_rules('contact','Name','required|is_numeric|min_length[10]|max_length[10]');
$this->form_validation->set_rules('email','Name','required|valid_email');
$this->form_validation->set_rules('gender','Name','required');
$this->form_validation->set_rules('city','Name','required');
$this->form_validation->set_rules('hobby','Name','required');

if($this->form_validation->run()==false)
{
$data['aaa']=$a;
   $this->load->view('edit',$data);
}
else
{
$abc['upload_path']='upload';
$abc['allowed_types']='png|jpg|jpeg|gif';

       $this->load->library('upload',$abc);
if(!$this->upload->do_upload('image'))
{
$file=$_POST['old_image'];
}
else
{
$file=$this->upload->file_name;
}
$abc=array('username'=>$_POST['username'],'password'=>$_POST['password'],'address'=>$_POST['address'],'contact'=>$_POST['contact'],'email'=>$_POST['email'],'gender'=>$_POST['gender'],'city'=>implode(',',$_POST['city']),'hobby'=>implode(",",$_POST['hobby']),'image'=>$file);
$this->dbabc->update($abc,$a);
redirect('abc/view');
}
}

}

?>

No comments:

Post a Comment