我有一个寄存器视图和一个寄存器控制器和一个标题。在标题有一个下拉菜单。
现在,当我从header nav下拉菜单中点击登录按钮时,它不会做任何事情,它只会刷新页面,而不会将我带到登录或注册页面。(这对于我的所有其他视图和控制器都是如此。
即使当我导航到硬编码的URL,如/register/login,它给我404页未找到错误
如何在控制器中正确加载视图,然后从视图中导航到这些视图。
我做错了什么?
下面是我的代码:
控制器为register.register.php:
class Register extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->library(array(
'session',
'email',
'form_validation',
));
$this->load->database();
$this->load->helper(array(
'url',
'string',
));
$this->load->model(array(
'auth_model',
'user_model',
'price_ranges_model',
'category_model',
'quote_model',
));
}
public function index()
{
$this->load->view('footer', array(
'page_title' => 'Register',
));
$this->load->view('register', array(
'price_ranges' => $this->price_ranges_model->get(),
'categories' => $this->category_model->get(),
'delivery_timings' => $this->user_model->_delivery_timings,
));
$this->load->view('footer');
}
public function login()
{
$this->form_validation->set_rules('c_username', 'Username', 'required');
$this->form_validation->set_rules('c_password', 'Password', 'required');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('header', array(
'page_title' => 'Register',
));
$this->load->view('register', array(
'price_ranges' => $this->price_ranges_model->get(),
'categories' => $this->category_model->get(),
'delivery_timings' => $this->user_model->_delivery_timings,
));
$this->load->view('footer');
}
register.php视图:
<div class="col_two_third col_last nobottommargin">
<h3>Don't have an Account? Register Now.</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Unde, vel odio non dicta provident sint ex autem mollitia dolorem illum repellat ipsum aliquid illo similique sapiente fugiat minus ratione.</p>
<form class="nobottommargin" method="post" action="<?=site_url('register/post')?>">
<div class="col_half">
<label for="register-form-name">Customer Name:</label>
<input type="text" id="qname" name="name" value="<?=set_value('name')?>" class="form-control" />
<?php echo form_error('name'); ?>
</div>
<div class="col_half">
<label for="register-form-email">Email Address (Username):</label>
<input type="email" id="qemail" name="email" value="<?=set_value('email')?>" class="form-control" />
<?php echo form_error('email'); ?>
</div>
<
<div class="col_half">
<label for="register-form-password">Password:</label>
<input type="password" id="qpassword" name="password" value="" class="form-control" />
<?php echo form_error('password'); ?>
</div>
<div class="col_half col_last">
<label for="register-form-cpassword">Confirm Password:</label>
<input type="password" id="qcpassword" name="password_confirm" value="" class="form-control" />
<?php echo form_error('password_confirm'); ?>
</div>
<?php echo form_error('est_amount'); ?>
</div>
header.php视图:
<div class="top-links on-click">
<form class="form-inline m-0" method="post" action="<?=base_url('register/login')?>">
<div class="form-group m-2">
<input type="email" class="form-control form-control-sm" placeholder="Username" name="c_username" required>
</div>
<div class="form-group m-2">
<input type="password" class="form-control form-control-sm" placeholder="Password" name="c_password" required>
</div>
<button type="submit" class="btn btn-sm btn-primary m-2">GO</button>
</form>
</div><!-- .top-links end -->
1条答案
按热度按时间rks48beu1#
我认为你应该检查你的基本网址。
您浏览的URL中有index.php吗?例如
或者您已经将index.php放在了application/config/config.php文件中,baseurl为
或者,您也可以在.htaccess文件(如this)中对其进行配置。
另外,对于视图,我建议不要一次又一次地从函数中加载它们。
尝试在视图中加载它们,如
在register.php中