Welcome Guest, Not a member yet? Register   Sign In
Making data available in ALL views
#1

I am attempting to make some data available in all view files. This information is displayed in the page masthead and sidebar menu. I know I could pull the data in each and every single controller, but that is tedious and really not efficient. I would like to pull it at some global point and have it available in the view. 
The key is I don't want to have to modify all the controllers to pass the data to the view (or remember to pass in the future). How can I set a variable that is available in a view in say the base controller?
What I have so far (in the base controller):

PHP Code:
class BaseController extends Controller
{

 protected 
$helpers = ["form""auth""phone""text"];

 public 
$siteInfo;

 public function 
initController(RequestInterface $requestResponseInterface $responseLoggerInterface $logger)
 {

 
parent::initController($request$response$logger);

 
$session = \Config\Services::session();

 
helper('siteinfo');
 
$this->siteInfo siteinfo();
 } 
Then in the view I have:
PHP Code:
<?= $siteInfo ?>

I have confirmed that $siteInfo has data before you get to the view, but in the view I get: "Undefined variable $siteInfo"
Feels like I am missing something simple here... help!
Reply


Messages In This Thread
Making data available in ALL views - by SoccerGuy3 - 06-14-2021, 03:50 PM



Theme © iAndrew 2016 - Forum software by © MyBB