You should create a Page_Controller in /application/core/Page_Controller.php
And extend it from every controller you wan't to access that data with.
PHP Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Page_Controller extends CI_Controller
{
protected $page_id;
}
PHP Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Groups extends Page_Controller {
...
}
I just re-read your question. And yes that's how you are supposed to use them.
You should however execute anotherFunction() inside the controller instead of Ajax, as people can just omit executing them.
PHP Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Groups extends CI_Controller {
public function view($slug = false){
$this->load->model('some_random_model'); //Loading model
$info = $this->some_random_model->get_info($slug); //Getting more info
$this->anotherFunction($info['page_id'])
}
private function anotherFunction($page_id){
//Some code here
$this->load->view('group/anotherFunction');
}
}
Or like this.
PHP Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Groups extends CI_Controller {
private $page_id = ''; //
public function view($slug = false){
$this->load->model('some_random_model'); //Loading model
$info = $this->some_random_model->get_info($slug); //Getting more info
$this->page_id = $info['page_id']; //Setting a value in page_id variable
$this->anotherFunction();
}
private function anotherFunction(){
$page_id = $this->page_id;
//Some code here
$this->load->view('group/anotherFunction');
}
}