我編寫了代碼,用於檢查用戶是否具有DB中的所有必需信息。如果用戶有,什麼都不做,但是如果他們是空的,重定向到continueregistration
頁面。但是,當它重定向它寫道,重定向到代碼錯誤的url
本頁面無法正常工作
本地主機重定向你太多次。嘗試清除您的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 – inarilo