problem in redirect method - El Forum - 01-26-2012
[eluser]asmaa kamal[/eluser]
hi
i try to code login page to website
i got this error
Quote:Not Found
The requested URL /t/main/login was not found on this server.
i got this error if i login by accepted email, password or if i login by unaccepted one
this is main code(in controller)
Code: <?php
class Main extends CI_Controller {
function Main()
{
parent::__construct();
$this->load->model('user_model');
}
public function login()
{
$this->form_validation->set_rules('userEmail','email','trim|required|valid_email|callback_check_login');
$this->form_validation->set_rules('userPassward','passward','trim|required');
if($this->form_validation->run())
{
if($this->user_model->Login(array('userEmail'=>$this->input->post('userEmail'),'userPassward'=>$this->input->post('userPassword'))));
{redirect('dashboard');}
redirect('main/login');}
$this->load->view('main/login_form');
}
function index()
{
$this->load->view('main/main_index');
}
function _check_login($userEmail)
{
if ($this->input->post('userPassward'))
{
$user=$this->user_model->GetUsers(array('userEmail'=>$userEmail,'userPassward'=>md5($this->input->post('userPassword'))));
if($user) return true;
}
$this->form_validation->set_message('_check_login','your username/passward is invalid.');
return false;
}
}
and this is view code
Code: <?php echo form_open(base_url() . 'main/login')?>
<fieldset>
<legend>Login Form </legend>
<ul>
<li>
<label>Email</label>
<?php echo form_input('userEmail',set_value('userEmail'))?>
<?php echo form_error('userEmail')?>
</li>
<li>
<label>password</label>
<?php echo form_password('userPassword')?>
<?php echo form_error('userPassword')?>
</li>
<li>
<?php echo form_submit('','login')?>
</li>
</ul>
</fieldset>
<?form_close()?>
and this is model code
Code: <?php
class User_Model extends Model {
function _required($required,$data)
{
foreach($required as $field)
if(!isset($data[$field])) return false;
return true;
}
function AddUser($options=array())
{
if(!$this->_required(array('userEmail','userPassword'),$options)) return false;
$options=$this->_default(array('userStatus','active'),$options);
$this->db->insert('users',$options);
return $this->db->insert_id();
}
function UpdateUser($options=array())
{
if(!$this->_required(array('userId'),$options)) return false;
if(isset($options['userEmail']))
$this->db->set('userEmail',$options['userEmail']);
if(isset($options['userPassword']))
$this->db->set('userPassword',md5($options['userPassword']));
if(isset($options['userStatus']))
$this->db->set('userStatus',$options['userStatus']);
$this->db->update('users');
return $this->db->affected_rows();
}
function _default($defaults,$options)
{
return array_merge($defaults,$options);
}
function GetUsers($options=array())
{
if(isset($options['userId']))
$this->db->where('userId',$options['userId']);
if(isset($options['userEmail']))
$this->db->where('userEmail',$options['userEmail']);
if(isset($options['userStatus']))
$this->db->where('userStatus',$options['userStatus']);
if(isset($options['userPassword']))
$this->db->where('userPassword',$options['userPassword']);
if(isset($options['limit'])&&isset;($options['offset']))
$this->db->limit($options['limit'],$options['offset']);
else if(isset($options['limit']))
$this->db->limit($options['limit']);
if(isset($options['sortBy'])&&isset;($options['sortDirection']))
$this->db->order_by($options['sortBy'],$options['sortDirection']);
$query=$this->db->get('users');
if(isset($options['userId'])||isset($options['userEmail']))
return $query->row(0);
return $query->result();
}
function Login($options=array())
{
if(!$this->_required(array('userEmail','userPassword'),$options)) return false;
$user=$this->GetUsers(array('userEmail'=>$options['userEmail'],'userPassword'=>md5($options['userPassword'])));
if(!$user) return false;
$this->session->set_userdata('userEmail',$user->userEmail);
$this->session->set_userdata('userId',$user->userId);
return true ;
}
}
?>
i think the problem in redirect method ( in main in controller) but when i stop this part i got the same error and when i try this
Code: if($this->user_model->Login(array('userEmail'=>$this->input->post('userEmail'),'userPassward'=>$this->input->post('userPassword'))));
{redirect('index.php/dashboard');}
redirect('index.php/main/login');}
plz help me
thanks
problem in redirect method - El Forum - 01-27-2012
[eluser]Jason Stanley[/eluser]
What is your base url? Is your site nested in a folder called 't'?
problem in redirect method - El Forum - 01-27-2012
[eluser]asmaa kamal[/eluser]
iam working at "local host" using wamp
the folder t is codeigniter folder it contains (application-system-userguide)
look at this
Code: $config['base_url'] = '';
$config['index_page'] = '';
$config['url_suffix'] = '';
problem in redirect method - El Forum - 01-27-2012
[eluser]Jason Stanley[/eluser]
Why haven't you filled out the base url?
Its Step 3 on the installation instructions.
http://ellislab.com/codeigniter/user-guide/installation/index.html
This will probably solve your problem. Currently it looks like CI is interpreting your directory as a controller.
problem in redirect method - El Forum - 01-27-2012
[eluser]asmaa kamal[/eluser]
i put it
$config['base_url'] = 'wathba.team'or 't' or 'index.php';
but it doesnt solve the problem
i dont know what i put in base url
i dont have url iam working at localhost
sorry iam beginner
problem in redirect method - El Forum - 01-27-2012
[eluser]Jason Stanley[/eluser]
What is the url to your codeigniter install?
Quote:http://localhost/t/
Is that it? What are you putting in the browser?
problem in redirect method - El Forum - 01-27-2012
[eluser]asmaa kamal[/eluser]
@jason Stanley
when i put :http://localhost/t/index.php/main/login
it give me the form
Email
password
i put email(true )exist in database
i got this message : Not Found
The requested URL /t/main/login was not found on this server.
and the url become :http://localhost/t/main/login
if i let textboxes blank and submit >> i got the same message
problem in redirect method - El Forum - 01-27-2012
[eluser]PhilTem[/eluser]
If you're working on wamp and have problems with the mod_rewrite, try to set 'index_page' to 'index.php' than it should solve your problem(s).
problem in redirect method - El Forum - 01-27-2012
[eluser]asmaa kamal[/eluser]
@PhilTem
i put
$config['index_page'] = 'index.php';
but the problem still exist
problem in redirect method - El Forum - 01-27-2012
[eluser]Jason Stanley[/eluser]
Your redirect code doesn't need the index.php in it.
Code: redirect('main/login')
You config options should look like this.
Code: $config['base_url'] = 'http://localhost/t/'; // The url of your local site.
$config['index_page'] = 'index.php';
|