Simple MVC system in 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
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 do it like so
- 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 you'll be able to do a <?php echo $variable_name; ?>
Technology:
Add new comment