Welcome Guest, Not a member yet? Register   Sign In
Global functions
#11

[eluser]mabright[/eluser]
OK. I tried this with error below.

Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined variable: CI

Filename: libraries/Location.php

Line Number: 31
A PHP Error was encountered

Severity: Notice

Message: Trying to get property of non-object

Filename: libraries/Location.php

Line Number: 31

Fatal error: Call to a member function userdata() on a non-object in

Code:

Code:
class Location {
    
    var $user_location;
    
    public function __construct()
    {
        $CI =& get_instance();
        $this->user_location = $this->get_user_location();
        ...
    }
    
    function get_user_location()
    {
        if($CI->session->userdata('location') == TRUE)
        {
            return $CI->session->userdata('location');
        }
        else
        {
                 ....
#12

[eluser]mddd[/eluser]
If you use $CI in one method, it is not set in another method! You need to make a class property $CI and, in your methods, refer to it as $this->CI.

Code:
class Location
{
   var $CI;

  function __construct()
  {
    $this->CI =& get_instance();
  }

  function other_function()
  {
    // use $this->CI here
  }
}
#13

[eluser]mabright[/eluser]
Wow...how much I still do not know...That did the trick, thanks alot...
#14

[eluser]mabright[/eluser]
I have this global variable working in my view but when I reference $data['variable_name'] in my controller or model, I get an undefined variable error.
#15

[eluser]cahva[/eluser]
If you're sending $data to view:
Code:
$data['variable_name'] = 'Foo';

$this->load->view('layout',$data);

..then you would reference it as $variable_name in the view.

EDIT: misread sorry. You ofcourse have to send the $data to your lib or model.
BTW, If you need some information in almost every page, you should concider MY_Controller technique where you extend from that. Or even better, take advantage of autoloading classes in PHP5 and use technique described here by Phil Sturgeon.




Theme © iAndrew 2016 - Forum software by © MyBB