Probably an easy one - PHP/CodeIgniter 'Undefined Variable'

Posted by Jack W-H on Stack Overflow See other posts from Stack Overflow or by Jack W-H
Published on 2010-04-19T11:10:29Z Indexed on 2010/04/19 11:13 UTC
Read the original article Hit count: 427

Filed under:
|

Morning y'all

This is probably an easy one but I barely got any sleep last night and am struggling to comprehend anything.

I've got a CodeIgniter library I've made called Points.php. Here's the contents of Points:

<?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 */ ?>

As you can see, I'm building it up slowly and it's being kept simple.

In one of my views, I want it to display the number of 'points' (which for the time being is simply the third segment of the URI). I call it like this:

<p>Points: <?php $params['user_id']=$this->uri->segment(3,1); echo $this->points->getpoints($params); ?></p>

The warning I get back in the view is this:

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: userid

Filename: libraries/Points.php

Yes I know it's such a simple problem but I've tried lots of things. Some variations include echoing in Points.php $params['userid']; etc. But I don't see what I'm doing wrong?

This is my first CodeIgniter class and I've fallen at the first step, haha...

© Stack Overflow or respective owner

Related posts about codeigniter

Related posts about php