so I was trying to save as an attribute of the class Profile.php the an specific uri segment but if I try this approach it doesn't work:
private $section=$this->uri->segment(2);
But this gives me the error:
unexpected '$section' (T_VARIABLE), expecting function (T_FUNCTION)
I have it right after declaring the class.
I did try another thing which is working so fat but I'll have to do this in every single method I create and I kinda wanted to have it declared only in the attribute so I don-t have to repeat code:
private $section;
public function account(){
$this->section=$this->uri->segment(2);
$this->routedHome($this->section);
}
Am I missing something here?
Use the __construct magic method. This is loaded on all requests.
<?php
class your_controller extends CI_Controller
{
private $section;
function __construct()
{
parent::__construct();
$this->section=$this->uri->segment(2);
}
}