可能是一个简单的PHP/CodeIgniter';未定义变量';
大家早上好 这可能很简单,但我昨晚几乎没睡,我正在努力理解任何事情 我制作了一个名为Points.php的CodeIgniter库。以下是要点的内容:可能是一个简单的PHP/CodeIgniter';未定义变量';,php,codeigniter,Php,Codeigniter,大家早上好 这可能很简单,但我昨晚几乎没睡,我正在努力理解任何事情 我制作了一个名为Points.php的CodeIgniter库。以下是要点的内容: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class Points { function __construct() { $this->ci =& get_instance();
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Points
{
function __construct()
{
$this->ci =& get_instance();
$this->ci->load->database();
}
function getpoints($params)
{
echo $userid;
}
}
/* End of file Points.php */
/* Location: ./application/libraries/Points.php */ ?>
正如你所看到的,我正在慢慢地建立它,并且保持简单
在我的一个视图中,我希望它显示“点”的数量(目前只是URI的第三段)。我这样称呼它:
<p>Points: <?php $params['user_id']=$this->uri->segment(3,1); echo $this->points->getpoints($params); ?></p>
点:
我在视图中得到的警告如下:
遇到一个PHP错误
严重性:通知
消息:未定义变量:userid
文件名:libraries/Points.php
是的,我知道这是一个很简单的问题,但我已经尝试了很多东西。一些变体包括在Points.php$params['userid']中回音;但是我不知道我做错了什么
这是我的第一门CodeIgniter课程,我在第一步就摔倒了,哈哈 应该是吗
function getpoints($params)
{
return $params['user_id']; // since you're passing the whole array
}
使用return
而不是echo
,您已经在另一端使用echo了应该是吗
function getpoints($params)
{
return $params['user_id']; // since you're passing the whole array
}
使用
return
而不是echo
,您已经在另一端使用echo了垃圾没有正确读取源代码,您需要将其作为数组而不是单个变量进行访问
$params['userid']
垃圾没有正确读取源代码,您需要将其作为数组而不是单个变量进行访问
$params['userid']
的可能重复