New to PHP, oop & codeigniter. My CI version is 3.1.2.
I am trying to load a library that I built, trying to understand Object oriented principles. Probably I'm missing something.
Below is my library.
<?php
class DPS {
private $mode;
public function __construct($params){
//print_r($params);
$this->mode = $params['mode'];
}
public function get_url(){
if($this->$mode == "TEST"){
return "https://uat.paymentexpress.com/pxaccess/pxpay.aspx";
} elseif($this->$mode == "LIVE"){
return "https://sec.paymentexpress.com/pxaccess/pxpay.aspx";
}
}
}
?>
I'm trying to access the get_url method in the controller below.
$params = [ 'mode' => 'TEST'];
$dps = $this->load->library('DPS',$params);
echo $dps->get_url();
Codeigniter is throwing the below error message.
Fatal error: Call to undefined method CI_Loader::get_url()
Being a newbie I'm probably missing some sort of OO fancy thingi. I just can't figure it out. Any help is greatly appreciated.
Thank you in advance
Try this,
$this->load->library('dps',$params);
echo $this->dps->get_url();
Always load libraries in Codeigniter like this
$this->load->library('library_name');
And call to method of library using
$this->library_name->method_name();
SO try like this...
Save your library in application/libraries
as Dps.php
.Then
$params = [ 'mode' => 'TEST'];
$dps = $this->load->library('dps',$params);
echo $this->dps->get_url();
And In your DPS
library. Correct it
public function get_url(){
if($this->mode == "TEST"){
return "https://uat.paymentexpress.com/pxaccess/pxpay.aspx";
} elseif($this->mode == "LIVE"){
return "https://sec.paymentexpress.com/pxaccess/pxpay.aspx";
}
}