I am really new to Codeigniter, and just learning from scratch. checked the documentation on Creating Libraries
but no success on my example:
I need to pass a value to __construct
library.
class: libraries/Myclasses/Bird
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Bird{
public $fly;
public $goodsound;
public function __construct($fly, $goodsound) {
$fly = $this->fly;
$goodsound = $this->goodsound;
}
public function sentance(){
return "This Bird can ".$this->fly . " and has ". $this->goodsound;
}
}
class: libraries/Mybird
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
require_once(APPPATH.'libraries/Myclasses/Bird.php');
class Mybird extends Bird {
public function __construct() {
}
}
controller: Birds
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Birds extends CI_Controller {
public function __construct(){
parent::__construct();
$config = array('fly' => 'fly', 'goodsound' => 'very good');
$this->load->library('Mybird', $config);
}
public function index(){
$mybird = new mybird();
echo $mybird->sentance();
}
}
I think that the problem is in Mybird class that not passing the values but i can't figure out how to handle it.