I tried this but couldn’t get it to work:
class Profile extends CI_Controller {
public function index() {
$foo = 'bar';
}
public function form_submit() {
echo $this->index()->foo;
}
}
I know I can make a variable accessible to all the methods in a class by declaring it outside all the methods at class level and declaring it as public. But here I need to declare the variable inside one of the methods.
If you are declaring it inside the method, you are out of luck unless you return the value.
A perhaps better alternative would be to declare it as an object variable (what you describe as “at class level”) but declare it private.