Simple-Mvc-System-Drupal-6
I’ve recently started working on a custom module in Drupal 6 and I really disliked the idea to use built in functions for tables and/or to use embedded html into my module. So I’ve made a simple system on having a view like system in Drupal 6.
Create a new module, and in the module folder create a directory called views (for eg:). Add the following function in your module
function get_include_contents($file, $file_data)
{
extract($file_data);
if (is_file($file)) {
ob_start();
include $file;
return ob_get_clean();
}
return false;
}
You can then use the function to include and assign variables to the view:
function mymodule_page()
{
$view = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'mymodule_page.php';
$view_data = array(
'variable_name' => 'data',
);
$page_content = get_include_contents($view, $view_data);
}
And then you’ll be able to just use the variable in your view
<?php echo $variable_name; ?>