SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Member mixo's Avatar
    Join Date
    Jul 2012
    Location
    United States of Russia
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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

  2. #2
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    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.

  3. #3
    SitePoint Member mixo's Avatar
    Join Date
    Jul 2012
    Location
    United States of Russia
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i want to know how to make /modules/ using MVC

  4. #4
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    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 Code:
    <?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.

  5. #5
    SitePoint Member mixo's Avatar
    Join Date
    Jul 2012
    Location
    United States of Russia
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  6. #6
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    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

  7. #7
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    336
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Serenarules View Post
    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 Code:
    <?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.
    Actually, I would use the Observer pattern for install/uninstall routine:
    PHP Code:
        class Observable {
            private 
    $_event,
                    
    $_observers = array();
            
            final function 
    createEvent$event ) {
                
    $this->_event = (string) $event;
                
    $this->_notify();
            }

            final function 
    getEvent() {
                return 
    $this->_event;
            }    
        
            final function 
    attachObserver $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 
    updateObservable $subject );
        } 
    Then have a developer class that implements the Observer:
    PHP Code:
        class Module implements Observer {    

                   
    // Other methods....
        
            
    final function updateObservable $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:
    PHP Code:
        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:
    PHP Code:
    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') === ):
                        
    $this->set(substr($str'9'));
                    break;
                    case (
    strpos($str'deactivate') === ):
                        
    $this->delete(substr($str'11'));
                    break;
                }
            }            
        } 

  8. #8
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    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.

  9. #9
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    336
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mixo View Post
    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
    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:
    PHP Code:
        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 
            
    });
        } 

  10. #10
    SitePoint Addict FizixRichard's Avatar
    Join Date
    May 2003
    Location
    UK
    Posts
    372
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by centered effect View Post
    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:
    PHP Code:
        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.
    FIZIX - Full Service Digital Agency - Engaging websites, apps and games.
    Follow us @FIZIXAgency

  11. #11
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,182
    Mentioned
    16 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Serenarules View Post
    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.
    Yep, for someone new to oop that solution is not practical. Keep it simple stupid…

  12. #12
    SitePoint Member mixo's Avatar
    Join Date
    Jul 2012
    Location
    United States of Russia
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  13. #13
    SitePoint Member mixo's Avatar
    Join Date
    Jul 2012
    Location
    United States of Russia
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •