我在http:localhost / my project上有一个登录页面。在使用服务器成功验证后,我想重定向到我放在另一个名为search.php的控制器(search_controller)中的视图。我可以在身份验证后成功加载我的搜索视图。问题是我在search.php中有另一个表单,在提交表单时我得到的对象没有找到'。
这是我的代码。 本地主机/ myproject的 默认控制器:欢迎
class Welcome extends CI_Controller {
public function index() {
$this->login();
}
public function login() {
$data['title'] = 'Login Form';
$this->form_validation->set_rules('user', 'Username', 'required|trim');
//other form validation rules
if ($this->form_validation->run() == FALSE) {
$this->load->view('login', $data);
} else {
$data['title'] = 'login form';
$username = $this->input->post('user');
$password = $this->input->post('password');
$company = $this->input->post('xdetail');
// authentication from server
if(somecondition)
$this->load->view('search');
}
}
我可以在搜索页面上查看内容。现在我在这个视图中有另一个表单,我在另一个容器中写了这个。 容器:Search_Controller
class Search_Controller extends CI_Controller {
public function index() {
$this->search();
}
public function search() {
$this->form_validation->set_rules('email', 'Email', 'valid_email');
//form validation rules
if ($this->form_validation->run() == FALSE) {
$this->load->view('search');
} else {
//get search Paraments here and put it in $data;
$this->load->view('search', $data);
}
}
}
现在当我点击提交按钮时,我找不到对象。 在搜索视图中,我有以下代码
//HTML script
echo validation_errors();
echo form_fieldset('Search Form');
$attributes = array('class' => 'email', 'id' => 'myform1', 'name'=>'sform');
echo form_open('',$attributes);
$emaildata=array(
'name'=>'email',
'id'=>'email_id',
'class'=>'email_class',
'size'=>'50',
'style'=>'width:150px'
);
$firstNamedata=array(
//attributes
);
$lastNamedata=array(
//attributes
);
echo'<label for="email">Email ID</label><br>'.form_input($emaildata).'<br>';
echo'<label for="firstName">First Name</label><br>'.form_input($firstNamedata).'<br>';
echo'<label for="lastName">Last Name</label><br>'.form_input($lastNamedata).'<br>';
echo br();
echo form_submit('mysubmit1','search');
echo form_close();
echo form_fieldset_close();
我不确定我在这里做错了什么。
更新:
我的.htaccess是:
IFModule mod_rewrite.c>
RewriteEngine On
RewriteBase /myproject/
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IFModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
答案 0 :(得分:0)
在您成功登录后,在控制器中放置一个重定向:
class Welcome extends CI_Controller {
public function index() {
$this->login();
}
public function login() {
$data['title'] = 'Login Form';
$this->form_validation->set_rules('user', 'Username', 'required|trim');
//other form validation rules
if ($this->form_validation->run() == FALSE) {
$this->load->view('login', $data);
} else {
$data['title'] = 'login form';
$username = $this->input->post('user');
$password = $this->input->post('password');
$company = $this->input->post('xdetail');
// authentication from server
if(somecondition)
redirect('search');
$this->load->view('search');
}
}