【发布时间】:2017-07-18 22:26:27
【问题描述】:
我编写了代码来检查用户是否在数据库中拥有所有必需的信息。如果用户有,什么也不做,但如果他们是空的,则重定向到continueregistration 页面。但是当它重定向时,它会写
此页面无法正常工作
localhost 将您重定向了太多次。尝试清除您的 cookie。 ERR_TOO_MANY_REDIRECTS
我清除了我的缓存它不起作用。这是我的看法:
<?php
if($this->session->userdata('logged_in')) {
$query = $this->db->get_where('instructors', array('id' => $this->session->userdata('id')));
$insdatacheck = $query->row_array();
if($insdatacheck['name'] == '') {
redirect('/user/continueregistration/');
} else { ?>
<script type="text/javascript">alert('hello');</script>
<?php
}
}
?>
和控制器:
function continueregistration() {
//set validation rules
$this->form_validation->set_rules('name', 'name', 'trim|required|alpha|min_length[2]|max_length[30]');
$this->form_validation->set_rules('web', 'web adress', 'trim|required|valid_url|prep_url|min_length[3]');
$this->form_validation->set_rules('facebook', 'facebook adress', 'trim|valid_url|prep_url|min_length[3]');
$this->form_validation->set_rules('twitter', 'twitter adress', 'trim|valid_url|prep_url|min_length[3]');
$this->form_validation->set_rules('youtube', 'youtube adress', 'trim|valid_url|prep_url|min_length[3]');
$this->form_validation->set_rules('instagram', 'instagram adress', 'trim|valid_url|prep_url|min_length[3]');
$this->form_validation->set_rules('tel', 'telephone number', 'trim|required|alpha_numeric_spaces|min_length[3]|max_length[30]');
$this->form_validation->set_rules('address', 'address', 'trim|required|alpha_numeric_spaces|min_length[3]|max_length[30]');
$this->form_validation->set_rules('insdescription', 'description', 'trim|required|alpha_numeric_spaces|min_length[3]');
$data['title'] = 'Continue Registration';
$data['instructors'] = $this->single_instructor_model->get_instructor_info();
$this->load->view('templates/header');
$this->load->view('registration/registration', $data);
$this->load->view('templates/footer');
//validate form input
if ($this->form_validation->run() == FALSE)
{
// fails
$this->load->view('templates/header');
$this->load->view('registration/registration', $data);
$this->load->view('templates/footer');
}
else
{
//insert the user registration details into database
$dataforreg = array(
'name' => $this->input->post('name'),
'web' => $this->input->post('web'),
'fb' => $this->input->post('facebook'),
'twitter' => $this->input->post('twitter'),
'youtube' => $this->input->post('youtube'),
'instagram' => $this->input->post('instagram'),
'phone' => $this->input->post('tel'),
'address' => $this->input->post('address'),
'description' => $this->input->post('insdescription')
);
// insert form data into database
if ($this->user_model->updateUser($dataforreg, $to_email)) {
redirect('homepage/index');
}
else
{
// error
$this->session->set_flashdata('msg','<div class="alert alert-danger text-center">Error</div>');
redirect('user/continueregistration');
}
}
}
【问题讨论】:
-
这意味着你有一个重定向循环
-
您对这段代码有什么看法?它实际上应该在控制器中。尽管。视图纯粹是为了展示。任何业务逻辑或流程控制都不应该出现在视图中。
-
你在 continueregistration 中调用 continueregistration
-
@inarilo 我在哪里称呼它?
-
@MilanMarkovic 它在 header.php 中
标签: php codeigniter redirect