There is no way to call any variables outside of view() method. You have to pass them into view() so it can reads your data.
If you have a property in your class, you have to pass it to data array in order to make it callable in view. Consider writing this code:
PHP Code:
<?php namespace App\Controllers;
use CodeIgniter\Controller;
class MyController extends Controller
{
public $globalVariable = 'I am callable';
public function index()
{
$data['global'] = $this->globalVariable;
return view('my_view', $data);
}
}
In your view, you can call it like any other variable:
PHP Code:
<div>
<p><?= $global ?></p>
</div>