im having some struggle with this matter, im using a custom built MVC that i built some years ago, and meanwhile ive been updating it, now ive managed a way to automatize most of the backoffice creations, but with this part im not able to pass some parameters.
This is an example of a module controller:
<?php
require_once("lib/controllers.php");
class defaultpage extends controllers
{
public $varx;
public function index()
{
global $website_name;
$filename = pathinfo(__FILE__, PATHINFO_FILENAME); // Obter o nome do ficheiro
if(isset($_SESSION['username'])){
$this->header("$website_name Banners");
$this->navbar();
$this->displayb("backoffice/modules/$filename/view/$filename.tpl.php",$image);
$this->footer();
}else{
header("Location: /", true, 301);
exit();
}
}
}
#######################################################################################
# CONFIGURAR PÁGINA EDITAR
#######################################################################################
if(isset($fetch)){
}else{
$fetch = NULL;
}
$image =
[ // 1º IMAGEM 2º LABEL 3ºName 4º ID
[
"../../".$fetch['imagem'],"Imagem(1000 x 940px)","fileToUpload","fileToUpload"
]
];
$textarea =
[ // 1º Label 2º Name 3º Value
[
"Conteudo PT","conteudo",utf8_decode($fetch['conteudo'])
],
[
"Conteudo EN","conteudo_en",utf8_decode($fetch['conteudo_en'])
]
];
$input =
[ // 1º Label 2º Name 3 º Value
[
"Link (Opcional)","link",utf8_decode($fetch['link']),"text"
]
];
#######################################################################################
$module = new defaultpage;
?>
So far so good, if i try to access this controller from an different controller it will work successfully, otherwise if in this viewer i try to access the $image,$textarea and $inputs to generate it returns me empty strings.
Notice: Undefined variable: image in /home/gmtemhic/test-domain.xyz/backoffice/modules/banner/view/banner.tpl.php on line 32
This is the part of the view file of the controller i posted above:
require_once("backoffice/modules/$table/controller/$table.php");
var_dump($image);
print_r($image);
Ive also tried to put a public function instead and pass it as a public variable in the class but still remains with no success.
You can use extract
function which imports variables into the current symbol table from an array. Example:
$variables = [
'color' => 'red',
'width' => 100,
'height' => 50
];
extract($variables);
echo 'Color: ' . $color;
echo 'Size: ' . $width . 'x' . $height;