Codeigniter can't get a simple post data variable
THIS IS FIXED, I h开发者_如何转开发ad named my function the same name as my controller, changed function name from login to do_login, now works a treat, thanks all
Hi this should be really simple:-
Im writing a php site using CI
im trying to get a simple POST variable im my controler using:
public function login()
{
$something = $this->input->post('something');
}
This on a controller name Login.php , the idea is have a form pass the POST data to this function at login/login, but I get this error
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Login::$input
Filename: controllers/login.php
Line Number: 38
( ! ) Fatal error: Call to a member function post() on a non-object in C:\wamp\www\rcity\application\controllers\login.php on line 38
Ive tried get_instance(), but I can refer to everything else as $this
inside the controller, as soon as I mention POST it dies, and off what ive read the input class is already loaded so thats not the issue, any ideas?
Thanks
HERES the full file for login.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Login extends CI_Controller {
public function index()
{
$data = array(
'title' => '*** | Login',
);
$this->load->helper('login_helper');
$this->load->view('head_view',$data);
if (check_login()==TRUE){$this->load->view('header_logged_in');}
else {$this->load->view('header_logged_out');}
$this->load->view('nav_view');
$this->load->view('login_view');
$this->load->view('footer_view');
}
public function login()
{
$something = $this->input->post('something');
$this->load->helper('login_helper');
}
}
You can't name your function the same as the controller... that would make it a constructor.
You're best best is to do this:
function __construct()
{
parent::__construct();
// the stuff you currently have in index()
}
public function index()
{
$this->login_user();
}
public function login_user()
{
// your code here
}
精彩评论