I am trying to call different methods within same controller written using Codeigniter through separate AJAX calls and create an object of a Third Library in one of those calls and later access the same object (also autoloaded SESSION library) in second method while making second AJAX Call:
Javascript has 2 separate AJAX Calls:
$.post('http://mysite.com/UserController/controllerA',{Param1:x,Param2:y});
$.post('http://mysite.com/UserController/controllerB');
And the controller looks like:
require_once 'FILEPATH/Thirdlibrary.php';
class UserController extends CI_Controller {
protected $service;
public controllerA{
$varA = $this->input->post('Param1');
$varB = $this->input->post('Param2');
$this->service = new ThirdLibray($varA,$varB);
$this->service->startCall();//Thirdlibrary has method startCall() and stopCall
}
public controllerB{
//I want to refer to the same object $this->service here
$this->service->stopCall();
}
Now I know that PHP re-initializes the objects each time its loaded/visited, how could I make this work.How to ovecome such error:
Call to a member function stopCall() on a non-object
(Querying here after making all the efforts searching and coding)