SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist stef25's Avatar
    Join Date
    Nov 2004
    Location
    belgium
    Posts
    465
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    visibility question, codeigniter

    i have a class called Admin with in it two methods. method one create() has a callback to method two called _do_upload. in _do_upload, $this->upload->data() returns an array of values that i want to be available in create().

    in _do_upload() i have $data = $this->upload->data(); so $data should be the array with the data i need. i return $data; but when i print_r($data) in create() i get an "undefined variable" error.

    how can i make $data available in create(). ive played around with setting $data as public or private but still cant make it visible.

    anyone know how?
    I need someone to protect me from
    all the measures they take in order to protect me

  2. #2
    SitePoint Addict
    Join Date
    Dec 2007
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use
    Code:
    $this->_data = $this->upload->data();
    and then access $this->_data in create().
    I'm creating trouble-free Apache, PHP, MySQL installer, WITSuite,
    and use it to setup my development environment.
    Demo, support, contact. Questions?

  3. #3
    SitePoint Evangelist stef25's Avatar
    Join Date
    Nov 2004
    Location
    belgium
    Posts
    465
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for your suggestion. im still getting the same error as with my original code:

    Message: Undefined property: Admin::$_data (Admin being the Class name)

    when i print_r($this->_data); exit; in the _do_upload function, it prints out all the array elements, so the variable holds the right data, its just not getting pased back to the create() function.

    do i have to declare this variable private or public or ... ? at the class or function level? also is there a reason why you use an underscore?
    I need someone to protect me from
    all the measures they take in order to protect me

  4. #4
    SitePoint Addict
    Join Date
    Dec 2007
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The code

    Code:
    class Admin
    {
      private $upload = null;
      private $_data = null;
      function __construct()
      {
        $this->upload = $this;
      }
      function create()
      {
        $this->_do_upload();
        print_r($this->_data);
      }
      function _do_upload()
      {
        $this->_data = $this->upload->data();
      }
      function data()
      {
        return 1;
      }
    }
    $admin = new Admin();
    $admin->create();
    should print 1.
    I'm creating trouble-free Apache, PHP, MySQL installer, WITSuite,
    and use it to setup my development environment.
    Demo, support, contact. Questions?

  5. #5
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,182
    Mentioned
    16 Post(s)
    Tagged
    4 Thread(s)
    PHP Code:
    class Admin
    {
      private 
    $_data null;
      function 
    __construct()
      {
      }
      function 
    create()
      {
        
    $this->_do_upload();
        
    print_r($this->_data);
      }
      function 
    _do_upload()
      {
        
    $this->_data $this->data();
      }
      function 
    data()
      {
        return 
    1;
      }
    }
    $admin = new Admin();
    $admin->create(); 


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •