Reputation: 3320
I'm attempting to use a method from another class. This question has been asked several times but in my case I get an error. I'm sure this is related to a mistake I've made.
class Reports_images extends Reports{
public function testOG(){
return('hi there');
}
}
In another file Reports.php:
require APPPATH.'/controllers/Reports_images.php';
public function appAddPics_post() {
$bakerboyTest = new Reports_images();
$bakerboy = $bakerboyTest->testOG();
$this->response($bakerboy ,REST_Controller::HTTP_OK);
}
I'm using CodeIgniter with a rest controller everything works except for this. I'm attempting to return a value from a method in another controller.
Upvotes: 0
Views: 35
Reputation: 618
That will never work. The Reports_Images class extends the Reports class, at the same time you call the testOG function of the Reports class.
This will work. Reports_images.php:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Reports_images extends CI_Controller{
public function testOG(){
return('hi there');
}
}
Then in other class Reports in Reports.php do this:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require APPPATH.'/controllers/Reports_images.php';
class Reports extends Reports_images{
public function appAddPics_post() {
$this->response($this->testOG(), REST_Controller::HTTP_OK);
}
}
Upvotes: 1