Hmvc vs mvc vc oop

Hello guys i am trying to develop modular website so i can upload modules & stuff like that im trying to make this on my MVC but not sure how to do this i want to keep default stuff (by that i mean login, posts, and sign-up form) in app folder and upload different modules to directory /modules/ please help

What exactly is your question(s)? How to implement MVC? How to organize folder structures? Or how to best to create modules? I apologize, but your post was a little vague.

i want to know how to make /modules/ using MVC

I assume these modules are to be designed such that third party people can author them? There are several things you’ll need to consider:

  1. How will these modules be used? (blocks like in PostNuke, or interceptors that change stock output, etc)
  2. Where will the output for the modules be displayed?
  3. Can one module affect the output of another?

Making these kinds of decisions first is going to be hard, and unfortunately, depends on you and your system. Nobody here can help with that.

However, once you’ve decided on these things, the next thing to do is create an interface for it. An small, but simple one, like the following:


<?php

interface IModule
{

    function Initialize(array $configuration);

    // installs new tables required by this module
    function Install($dbConn);

    // upgrades tables from a previous version
    function Upgrade($dbConn, $previousVersionInfo);

    // deinstalls the module tables
    function Deinstall($dbConn);

    // return array with major/minorrevision (E.G. 4.2.0)
    function CurrentVersionInfo();

    // returns a string of html
    function Render(array $arguments);

}

?>

It in it’s simplest form, that would be it. However, there is a lot more you could do with it, like hooks, managing block instances and so forth.

But this should get you headed in the right direction. The point is in providing a known interface for module authors to code against.

Hope it helps.

i got this but i need this:
if the module exist in the directory /modules/ for example modules/login.mod.php
i want to display on the main page Login without touching index.php file

There are a few ways to handle that.

  1. Use readdir() to iterate through the contents of the module folder, loading what you want. But this would grab all of them, and might not be what you want, or in the order you want. You may want to disable certain ones, or reorder them. So…

  2. Create an admin system that let’s you activate/deactivate installed modules, create instances of the module, and sequence them.

readdir reference: http://php.net/manual/en/function.readdir.php

Actually, I would use the Observer pattern for install/uninstall routine:


	class Observable {
		private $_event,
				$_observers = array();
		
		final function createEvent( $event ) {
			$this->_event = (string) $event;
			$this->_notify();
		}

		final function getEvent() {
			return $this->_event;
		}	
	
		final function attach( Observer $observer ) {
			$i = array_search($observer, $this->_observers);
			if ($i === false) {
				$this->_observers[] = $observer;
			}
		}		
		
		final private function _notify() {
			foreach($this->_observers as $observer) {
				$observer->update( $this );
			}			
		}
	}
	
	interface Observer {
		function update( Observable $subject );
	}

Then have a developer class that implements the Observer:

	
	class Module implements Observer {	

               // Other methods....
	
		final function update( Observable $subject ) {
			switch( $subject->getEvent() ) {
				case( 'activated_' . $this->_name ):
					if( method_exists($this, 'install') ) {
						$this->install();
					}
				break;
				case( 'deactivated_' . $this->_name  ):
					if( method_exists($this, 'uninstall') ) {
						$this->uninstall();
					}
				break;				
			}
		}
	}

The developer implements the Module class:


	class TestModule extends Module {
		function uninstall() {
			echo '<br>TestModule uninstalling';
		}
	}

	class TestOne extends Module {
		function install() {
			echo '<br>TestOne installing';
		}
		function uninstall() {
			echo '<br>TestOne uninstalling';
		}
	}

	class TestTwo extends Module {
		function install() {
			echo '<br>TestTwo installing';
		}
		function uninstall() {
			echo '<br>TestTwo uninstalling';
		}
	}

Then, for the admin side, when an admin installs/uninstalls the module it will trigger an event:

final class AdminModules {
		private $_active; // Active modules

		function __construct() {
			$this->_active = Modules::getAll();
		}
		
		final function load() {
			foreach( $this->_active as $p ) {

				$file = MODULE_PATH. '/' .$p. '/index.php';

				if( file_exists( $file ) ) {
					require( $file );
					
					if( class_exists($p) ) {
						$i = new $p;
						// Attach the observer
						$this->attach($i);
					}					
				}
			}		
		} 

		final protected function set( $addon ) {
			Modules::set( $addon );
			$this->createEvent('activated_' . $addon);
		}
		
		final protected function delete( $addon ) {
			Modules::delete( $addon );
			$this->createEvent('deactivated_' . $addon);			
		}	

		final function process( $str ) {
			switch (true) {
				case (strpos($str, 'activate') === 0 ):
					$this->set(substr($str, '9'));
				break;
				case (strpos($str, 'deactivate') === 0 ):
					$this->delete(substr($str, '11'));
				break;
			}
		}			
	}

Certainly, but I get the sense that that may be a bit above the OP, given the nature of his question, don’t you think? Don’t scare him away. If I’m wrong in my assumption, then yes, there are more elegant solutions.

You can possible use a hook method ala WordPress - if the module is an active one, then load the module. When the hook is called, the module will start, then you could use a router to run the code.

For example:


	class TestModule extends Module {
		function __construct() {
			$this->filter('sidebar_hook', 'fn_to_run_at_login');
		}	
	}

	function fn_to_run_at_login() {
		Router::add('login', function() {
			// do something 
		});
	}

This is something like what I was going to say (my framework uses a deep hook approach to plugins, which can inject into the template engine if its being used), though as Serenarules pointed out such solutions may be above the OP given their post.

Yep, for someone new to oop that solution is not practical. Keep it simple stupid…

thanks alot guys i have been studying php over 6 months know im trying to do something practical, i got this stuff pretty easy i even wrote my framework its not simple and not advance now im trying to module & plugin system thanks again keep looking forward

also one more thing im trying to find a really good tutorial on bootstrap to get the url and redirect on module view page something like this

$url = filter_var($_GET[‘url’], FILTER_SANITIZE_URL);

and check if the url exist.