It's really convenient how MVC patterns allow you to define view a and then load variables into it via the controller. For the sake of argument let us take CodeIgniter as an example:
Controller:
Class Example extends CI_controller(){ function show_page(){ $data = array('msg'=>'Hello World'); echo $this->load->view('hello',$data); } } View (hello.php):
<h1><?php echo $msg; ?></h1> I have taken over an old project written years ago where there are redundant html code everywhere. It has no pattern whatsoever just straight up poorly structured code.
I wanted to create a class that has a function that will fetch all HTML code from a file in one folder, feed variables to them and show the result. Like so:
Folder structure:
View_folder - hello.php Class - view_class.php` Main:
<?php $data['msg'] = 'Hello World!'; echo $view_class->get_view('hello.php',$data); ?> Is it possible to achieve this? Can someone give an example function on how to do this. Thanks.