Php 编码点火器注册
当我注册时,重定向到另一页。但是,我刷新了那个页面,它转到了Php 编码点火器注册,php,codeigniter,Php,Codeigniter,当我注册时,重定向到另一页。但是,我刷新了那个页面,它转到了索引页面。这是错误。请提供此问题的解决方案 控制器 public function register() { $this->load->view('index'); } public function do_register() { $this->load->library('form_validation'); $this-&g
索引页面。这是错误。请提供此问题的解决方案
控制器
public function register()
{
$this->load->view('index');
}
public function do_register()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('uname', 'Username', 'required|min_length[4]|max_length[15]');
$this->form_validation->set_rules('mail', 'Email', 'required|valid_email');
$this->form_validation->set_rules('pass', 'Password', 'required|min_length[4]');
$this->form_validation->set_rules('titleimg','Title','required|min_length[4]');
$this->form_validation->set_rules('descrip', 'Description', 'required|min_length[4]');
if($this->form_validation->run() == FALSE)
{
$data=$this->data;
$data['error']= '' ;
$this->load->view('index',$data);
}
else
{
$path = $_FILES['image']['name'];
$imgext=strtolower(strrchr($path,'.'));
$imgname= $this->generateRandomString().$imgext;
/* echo "imgname".$imgname;
die();*/
if($path!='')
{
$im= $this->config->item('base_url').'/uploads'.'/'.$imgname;
$x=$this->do_upload($imgname);
$data['img']=$im;
if ($x['error']=='')
{
$this->user_model->register_user($data['img']);
$this->load->view('register_view');
}
else
{
$data['error']= $x['error'] ;
$this->load->view('index',$data);
}
}
}
}
function generateRandomString()
{
$characters = '0123456789abcdefghijklmnopqrstuvwxyz';
$randomString = '';
for ($i = 0; $i < 8; $i++) {
$randomString .= $characters[rand(0, strlen($characters) - 1)];
}
return $randomString;
}
function do_upload($img)
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
//$config['max_size'] = '2048000';
//$config['max_size'] = '1048576 ';
$config['max_size'] = '1024 ';
$config['file_name'] = $img;
$this->load->library('upload',$config);
//$this->upload->data('image');
//print_r("Hello->". $config['upload_path']);
//die();
//print_r("Hello12345->".$this->upload->do_upload('image'));
// die();
if ( ! $this->upload->do_upload('image'))
{//echo"333333".$this->upload->do_upload('image');
//die();
$error = array('error' => $this->upload->display_errors());
$data['error']=$error;
return $data;
//return $error;
}
else
{
//print_r("Hell11o->".$this->upload->data());
// die();
$data = array('upload_data' => $this->upload->data());
//$this->load->view('register_view',$data);
$data['error']='';
return $data;
}
return;
}
公共函数寄存器()
{
$this->load->view('index');
}
公共函数do_register()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('uname','Username','required |最小长度[4]|最大长度[15]);
$this->form_validation->set_规则('mail'、'Email'、'required';valid_Email');
$this->form_validation->set_规则('pass','Password','required | min_length[4]);
$this->form_validation->set_rules('titleimg'、'Title'、'required | min_length[4]);
$this->form_validation->set_规则('descrip','Description','required | min_length[4]);
如果($this->form\u validation->run()==FALSE)
{
$data=$this->data;
$data['error']='';
$this->load->view('index',$data);
}
其他的
{
$path=$\u文件['image']['name'];
$imgext=strtolower(strrchr($path,'.');
$imgname=$this->generateRandomString()。$imgext;
/*回声“imgname”。$imgname;
模具();*/
如果($path!='')
{
$im=$this->config->item('base_url')。/uploads'./'。$imgname;
$x=$this->do_upload($imgname);
$data['img']=$im;
如果($x['error']='')
{
$this->user\u model->register\u user($data['img']);
$this->load->view('register_view');
}
其他的
{
$data['error']=$x['error'];
$this->load->view('index',$data);
}
}
}
}
函数GeneratorDomainString()
{
$characters='0123456789abcdefghijklmnopqrstuvwxyz';
$randomString='';
对于($i=0;$i<8;$i++){
$randomString.=$characters[rand(0,strlen($characters)-1)];
}
返回$randomString;
}
函数do_upload($img)
{
$config['upload_path']='./uploads/';
$config['allowed_types']='gif | jpg | png';
//$config['max_size']='2048000';
//$config['max_size']='1048576';
$config['max_size']='1024';
$config['file_name']=$img;
$this->load->library('upload',$config);
//$this->upload->data('image');
//打印(“你好->”$config['upload\u path']);
//模具();
//打印($this->upload->do_upload('image'));
//模具();
如果(!$this->upload->do_upload('image'))
{//echo“333333”。$this->upload->do_upload('image');
//模具();
$error=array('error'=>$this->upload->display_errors());
$data['error']=$error;
返回$data;
//返回$error;
}
其他的
{
//打印($this->upload->data());
//模具();
$data=array('upload_data'=>$this->upload->data());
//$this->load->view('register\u view',$data);
$data['error']='';
返回$data;
}
返回;
}
视图:
寄存器
登记
将此更改为
if ($x['error']=='')
{
$this->user_model->register_user($data['img']);
redirect('home/registersuccess');
}
编写新函数
function registersuccess(){
$this->load->view('register_view');
}
您可以粘贴
html代码吗?是的,我为表单设置了操作成功注册后使用重定向和创建新函数调用viewuser1048123如何使用重定向和创建新函数调用view?
if ($x['error']=='')
{
$this->user_model->register_user($data['img']);
redirect('home/registersuccess');
}
function registersuccess(){
$this->load->view('register_view');
}