Welcome Guest, Not a member yet? Register   Sign In
custom library with parameters : problem
#1

(This post was last modified: 11-13-2015, 06:17 AM by casa.)

hello,
i want to use custom libray with parameters on its constuctor. I've a fatal error.

My libray class (in folder library)
PHP Code:
// class file named Example.php
defined('BASEPATH') OR exit('No direct script access allowed');
class 
Example   
    private $items

 
   
    public 
function __construct($args) {
 
       $this->items $args;
 
   }
 
   
    public 
function get($key) {
 
       if(is_array($this->items) && array_key_exists($key$this->items)) {
 
           return $this->items[$key];
 
       } else {
 
           return $this->items;
 
       }
 
   }


My test view page
PHP Code:
//view file :  my_view.php
$params = array('red''green');
$this->load->library('Example'$params);

// Fatal error: Call to a member function get() on a non-object
echo $this->example->get(0) ;  
// but if i do this
$e = new Example($params);
echo 
$e->get(0) ; // it works 
Can you help me please.
Thank you.
Reply


Messages In This Thread
custom library with parameters : problem - by casa - 11-13-2015, 03:27 AM



Theme © iAndrew 2016 - Forum software by © MyBB