Codeigniter 无法获取简单的后数据变量
这是固定的,我将我的函数命名为与我的控制器相同的名称,将函数名称从登录更改为 do_login,现在可以使用了,谢谢大家
嗨,这应该非常简单:-
我正在使用 CI 编写一个 php 站点,
我正在尝试获取我的控制器使用一个简单的 POST 变量:
public function login()
{
$something = $this->input->post('something');
}
这在控制器名称 Login.php 上,想法是有一个表单在登录/登录时将 POST 数据传递到此函数,但我收到此错误
遇到 PHP 错误
严重性:通知
消息:未定义的属性: 登录::$输入
文件名:controllers/login.php
行号:38
( ! ) 致命错误:呼叫成员 在非对象上使用 post() 函数 C:\wamp\www\rcity\application\controllers\login.php 第 38 行
我尝试了 get_instance(),但我可以将控制器内的其他所有内容引用为 $this
,一旦我提到 POST,它就会消失,并且我读到的输入类已经加载所以这不是问题,有什么想法吗?
感谢
这里有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');
}
}
THIS IS FIXED, I had 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::$inputFilename: 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');
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能将函数命名为与控制器相同的名称...这将使其成为构造函数。
你最好最好这样做:
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: