html - PHP login using CodeIgniter -
i'm trying login on php using codeigniter.
my code this:
login view
<div class="section section_with_padding" id="usuarios"> <h1>acceso usuarios</h1> <div class="half left"> <h4>usuario existente</h4> <p>si posee una cuenta en garage, introduzca su nombre de usuario y contraseña para acceder.</p> <div id="login"> <!-- usado para que muestre los errores de validacion --> <form method="post" name="users" action="index.php/verificarlogin"> <div class="left"> <label for="username">nombre de usuario:</label> <input name="username" type="text" class="required input_field" id="username" maxlength="30" required/> </div> <div class="right"> <label for="password">contraseña:</label> <input name="password" type="password" class="validate-email required input_field" id="email" maxlength="30" required/> </div> <div class="clear"></div> <input type="submit" class="submit_btn float_l" name="submit" id="submit" value="entrar" /> </form> </div> </div>
don't mind right div, code still not coded...
my verificarlogin (verify login) controller
<?php if ( ! defined('basepath')) exit('no direct script access allowed'); class verificarlogin extends ci_controller { function __construct() { parent::__construct(); $this->load->model('usuarios','',true); } function index() { //este metodo tendra las credenciales de validacion $this->load->library('form_validation'); $this->form_validation->set_rules('username', 'username', 'trim|required|xss_clean'); $this->form_validation->set_rules('password', 'password', 'trim|required|xss_clean|callback_check_database'); if($this->form_validation->run() == false) { //si la validacion falla, el usuario es redireccionado la pagina de login $this->load->view('#usuarios'); } else { //si la validacion pasa, el usuario es redireccionado donde deberia ir redirect('home_usuarios', 'refresh'); } } function check_database($password) { //si la validacion de campo es exitosa, valida contra la base de datos $username = $this->input->post('username'); //pregunta en la base de datos $result = $this->user->login($username, $password); if($result) { $sess_array = array(); foreach($result $row) { $sess_array = array( 'id' => $row->id, 'username' => $row->username ); $this->session->set_userdata('logged_in', $sess_array); } return true; } else { $this->form_validation->set_message('check_database', 'nombre de usuario o contraseña invalida'); return false; } } }
when run it gives error:
a php error encountered
severity: notice
message: undefined property: verificarlogin::$form_validation
filename: controllers/verificarlogin.php
line number: 32
the line error marking this:
$this->form_validation->set_rules('username', 'username', 'trim|required|xss_clean');
i have reserch , found error caused because lacks line
$this->load->library('form_validation');
but line in code...
the libraries database , session loaded autoload.
i don't know whan i'm doing wrong... it's code can't access libraries...
if documentation can see example:
<?php class form extends ci_controller { function index() { $this->load->helper(array('form', 'url')); $this->load->library('form_validation'); if ($this->form_validation->run() == false) { $this->load->view('myform'); } else { $this->load->view('formsuccess'); } } } ?>
and $this->form_validation
, not $this->form_validation
try changing name of property wanna access.
also try fix name when loading library $this->load->library('form_validation');
Comments
Post a Comment