Include php array in controller


#1

What is the correct way to include a php array in the controller? Simply including it like this is not working

$kenmerken = include('../src/1_vakantie-en-recreatie.php');

#2

That line of code looks alright. I guess the array in that file is wrong. It should be something like:

<?php return [ ];

#3

A common issue with relative includes is that the file isn’t where you expect it to be.
It is the best to make path absolute by making it relative to directory of current file:

$kenmerken = include(__DIR__ . '/../src/1_vakantie-en-recreatie.php');

#4

Thanks, but also not working :frowning:


#6

Worst case, instead of the include, try a

var_dump(__DIR__); die;

That should at least tell you what the path is from where you start building out the include.

Just to make sure, you are on linux/unix/IBMi/Mac?
In case you are on Windows, maybe try
realpath(__DIR__)


#7

With assumption, your controller is in the src/Controller directory, and the file in src directory, you can do:

// up 1 directory first
include realpath(__DIR__ . '/../1_vakantie-en-recreatie.php');