SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Aug 2003
    Location
    Sydney
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    User Registration

    Im currently looking at howto layout the code for the User and User Registration part of my site.

    I was wondering if it'd be better to have one model, User to handle it all.

    So it'd have user.{model,dao,gateway,manager,view}.php.

    Or should I seperate it into User and UserRegistration?

  2. #2
    Non-Member
    Join Date
    Jan 2004
    Location
    Planet Earth
    Posts
    1,764
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just keep it as one component, ie RegisterUser

    I arrive at this reason as you are only dealing with one individual component of your site, ie the registering of a new user, and this component is to do nothing more than that yes ?

    On another note, in my case, I use the Page Controller design pattern, and for something like this, I would proberly leave it as a module (mvc) it's self, rather than a Page Controller if you see what I mean ?

    ie In a template, I'd have a tag

    PHP Code:
    <user_register /> 
    Which a module controller would execute the RegisterUser module, and return a string (xHTML) back to the Page Controller, ready for the View to replace the tag with the string.

    A bit long winded but I hope this helps anyway

  3. #3
    SitePoint Zealot
    Join Date
    Aug 2003
    Location
    Sydney
    Posts
    187
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So therefore, splitting User into User and UserRegistration, User just handles the User when they've logged in through Auth, but UserRegistration handles the registration of the user.

    UserRegistration DAO would contain a CRUD and the User DAO would have a CRUD, but the create on User only happens when the user confirm the create in UserReg.

    Im looking at having.

    PHP Code:
    class UserRegistration {
     function UserRegistration () {}
     function setInstanceMemento () {}
     function getInstanceMemento () {}
     function validate () {}
     function getMissingFields () {}
     function getInvalidFields () {}
     function createConfirmCode () {}
     function createAntiSpamImage () {}
    }

    class UserRegistrationDao {
     function UserRegistrationDao () {}
     function create () {}
     function read () {}
     function delete () {}
    }

    class UserRegistrationManager {
     function UserRegistrationManager () {}
     function findRegistrationById () {}
    }

    register.php
    <?php
     
    require_once('common.php');
     
     
    $userreg = &new UserRegistration;
     
    $userregdao = &new UserRegistrationDao;
     
    $userregmgr = &new UserRegistrationManager($userreg$userregdao);

     
    $userregmgr->findRegistrationById($_GET['regid']);

     
    $memento $userreg->getInstanceMemento();
     if (
    $memento->conf_code == $_GET['conf_code']) {
      echo 
    "success";
     }

    ?>
    Last edited by ausurt; Feb 22, 2004 at 06:26.

  4. #4
    SitePoint Evangelist
    Join Date
    Dec 2003
    Location
    Arizona
    Posts
    411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Widow Maker
    Just keep it as one component, ie RegisterUser

    I arrive at this reason as you are only dealing with one individual component of your site, ie the registering of a new user, and this component is to do nothing more than that yes ?

    On another note, in my case, I use the Page Controller design pattern, and for something like this, I would proberly leave it as a module (mvc) it's self, rather than a Page Controller if you see what I mean ?

    ie In a template, I'd have a tag

    PHP Code:
    <user_register /> 
    Which a module controller would execute the RegisterUser module, and return a string (xHTML) back to the Page Controller, ready for the View to replace the tag with the string.

    A bit long winded but I hope this helps anyway
    Sounds interesting... I would like to see your Module Controller implementation for this problem if possible.

    Thanks,

    JT

  5. #5
    Non-Member
    Join Date
    Jan 2004
    Location
    Planet Earth
    Posts
    1,764
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, though it isn't by any means complete, pretty basic in fact for the moment

    Hoping to improve upon it soon though. Here though is what I have for the time being, enjoy

    PHP Code:
    # ./root/web/modules/essentials.class.php
        # essential application functionality

        
    class BasePgView {
            var 
    $error;
            var 
    $template;
            
            function 
    BasePgView$filename ) {
                
    $this -> error false;
                
                if( !
    file_exists$filename ) ) {
                    
    $this -> error true;
                }
                
    $fp = @fopen$filename'r' );
                
    $template = @fread$fpfilesize$filename ) );
                @
    fclose$fp );
                
                
    $this -> template = &$template;
            }
            
            function 
    IsError() {
                return 
    $this -> error;
            }
            
            function 
    Replace$tag$string ) {
                
    $this -> template ereg_replace$tag$string$this -> template );
            }
            
            function 
    Finalise() {
                if( !
    $this -> IsError() ) {
                    
    #
                    
    $this -> Replace'<page_date />'dateDATE_FULL ) );
                    echo( 
    $this -> template );
                    exit;
                }
            }
        }
        
        class 
    Module {
            var 
    $modules;
            var 
    $includes;
            
            function 
    Module() { 
                
    $this -> tags = array( '<page_news />' );
                
    $this -> includes = array( 'news/news.class.php' );
                
                
    $this -> Initialise();
            }
            
            function 
    Fetch() {
                return 
    $this -> modules;
            }
            
            function 
    Initialise() {
                
    $count 0;
                
    $modules['tags'] = $this -> tags;
                
                foreach( array( 
    'News' /* any given module(s) */ as $item ) {
                    include_once( 
    $this -> includes[$count] );
                    
    # execute a module controller and pass over model data to module view
                    
    $cntrl = &new $item;
                    
    #
                    
    $v $item.'View';
                    
    $v = &new $v$cntrl -> Fetch() );
                    
    $modules[$count] = $v -> Render();
                    
    $count++;
                }
                
    $this -> modules = &$modules;
            }
        }
        
        class 
    BaseModuleView {
            var 
    $error;
            var 
    $template;
            
            function 
    BaseModuleView$filename ) {
                
    $this -> error false;
                
                if( !
    file_exists$filename ) ) {
                    
    $this -> error true;
                }
                
    $fp = @fopen$filename'r' );
                
    $template = @fread$fpfilesize$filename ) );
                @
    fclose$fp );
                
                
    $this -> template = &$template;
            }
            
            function 
    IsError() {
                return 
    $this -> error;
            }
            
            function 
    Replace$tag$string ) {
                
    $this -> template ereg_replace$tag$string$this -> template );
            }
            
            function 
    Finalise() {
                if( !
    $this -> IsError() ) {
                    
    #
                    
    return $this -> template;
                }
            }
        } 
    PHP Code:
    require_once( 'implementation.class.php' );
        
        class 
    News {
            var 
    $model;
            
            function 
    News() {
                
    $this -> Execute();
            }
            
            function 
    Fetch() {
                return 
    $this -> model;
            }
            
            function 
    Execute() {
                
    $db = &db::getInstance(); 
                
    # implement model
                
    $this -> model FindByLimit::LoadGateway::FindByLimit( &$db ) );
            }
        }
        
        class 
    NewsView {
            var 
    $model;
            
            function 
    NewsView( &$model ) {
                
    $this -> model = &$model;
            }
            
            function 
    Render() {
                
    $html '';
                
                foreach( 
    $this -> model as $model ) {
                    
    $content = &new BaseModuleView'modules/news/templates/news.fragment.html' );
                
                    
    $content -> Replace'<id />'$model -> GetId() );
                    
    $content -> Replace'<date />'/* date filter */ dateDATE_SHORT$model -> GetDate() ) );
                    
    $content -> Replace'<title />'$model -> GetTitle() );
                    
    #
                    
    $html .= $content -> Finalise();
                }
                return 
    $html;         
            }
        } 
    PHP Code:
    # implementation models
        
        
    class Gateway 
            function 
    Gateway() {
            }
            
            function 
    FindById( &$db$id ) {
                
    $findById "SELECT 
                    id,
                    UNIX_TIMESTAMP(date) AS date, 
                    title, 
                    body FROM tbl_news WHERE id = '"
    .$id."'";
                    
                
    $statement $db -> Query$findById );
                
    #
                
    return $statement -> Execute();
            }
            
            function 
    FindByLimit( &$db$limit ) {
                
    $findByLimit "SELECT 
                    id, 
                    UNIX_TIMESTAMP(date) AS date, 
                    title, 
                    body FROM tbl_news ORDER BY date DESC LIMIT "
    .$limit;
                
                
    $statement $db -> Query$findByLimit );
                
    #
                
    return $statement -> Execute();
            }
        }
        
        class 
    Archiver 
            var 
    $ar;
            
            function 
    Archiver() {
                
    $this -> ar = array();
            }
            
            function 
    SetId$id ) {
                
    $this -> ar['id'] = $id;
            }
            
            function 
    SetDate$date ) {
                
    $this -> ar['date'] = $date;
            }
            
            function 
    SetTitle$title ) {
                
    $this -> ar['title'] = $title;
            }
            
            function 
    SetBody$body ) {
                
    $this -> ar['body'] = $body;
            }        
        }
        
        class 
    FindById {
            function 
    FindById() {
            }
            
            function 
    Load( &$resultset ) {
                
    $iterator = &new QueryIterator$resultset );
                
    $row $iterator -> GetCurrent();
                
    #
                
    $archive = &new ByIdArchive;
                
    $archive -> Invoke$row );
                
                return 
    $archive;
            }
        }
        
        class 
    FindByLimit 
            function 
    FindByLimit() {
            }
            
            function 
    Load( &$resultset ) {
                
    $indexer = array();
                
    $iterator = &new QueryIterator$resultset );
                
    #
                
    while( $iterator -> IsValid() ) { 
                    
    $row $iterator -> GetCurrent();
                    
    $iterator -> GetNext();
                    
    #
                    
    $archive = &new ByLimitArchive;
                    
    $archive -> Invoke$row );
                    
    #
                    
    $indexer[] = &$archive;
                } 
                return 
    $indexer;
            }
        }
        
        class 
    ByIdArchive extends Archiver 
            function 
    ByIdArchive() {
                
    Archiver::Archiver();
            }
            
            function 
    Invoke$row ) {
                
    $this -> SetId$row['id'] );
                
    $this -> SetDate$row['date'] );
                
    $this -> SetTitle$row['title'] );
                
    $this -> SetBody$row['body'] );
            }
            
            function 
    GetId() {
                return 
    $this -> ar['id'];
            }
            
            function 
    GetDate() {
                return 
    $this -> ar['date'];
            }
            
            function 
    GetTitle() {
                return 
    $this -> ar['title'];
            }
            
            function 
    GetBody() {
                return 
    $this -> ar['body'];
            }
        }
        
        class 
    ByLimitArchive extends Archiver 
            function 
    ByLimitArchive() {
                
    Archiver::Archiver();
            }
            
            function 
    Invoke$row ) {
                
    $this -> SetId$row['id'] );
                
    $this -> SetDate$row['date'] );
                
    $this -> SetTitle$row['title'] );
            }
            
            function 
    GetId() {
                return 
    $this -> ar['id'];
            }
            
            function 
    GetDate() {
                return 
    $this -> ar['date'];
            }
            
            function 
    GetTitle() {
                return 
    $this -> ar['title'];
            }
        } 
    The HTML template fragment required by a module view, ie News

    Code:
    <div id="newsurl"><date /></div>
    <div id="newsheading"><a href="news.php?task=findById&amp;id=<id />"><title /></a></div>
    And the part of the Page Controller which actually creates the instance of the Module class to build the seperate components.

    PHP Code:
    # ./root/web/index.php
        # page controller @ home page
        
        
    error_reportingE_ALL );
        
        
    # application configuration
        
    require_once( 'configure.php' );
        
        
    # core application libraries
        
    require_once( LIBRARY_DB ); 
        require_once( 
    LIBRARY_GD ); 
        require_once( 
    LIBRARY_SESSION ); 
        
        
    # application dependents
        
    require_once( REQUIRED_ESSENTIALS );
        
        class 
    Page {
            function 
    Page() {
            }
            
            function 
    Dispatch() {
                
    $page = &new PgController;
                
    $page -> Execute();
                
                
    $view = &new PgView;
                
    $view -> Render( new Module );
            }
            
            function 
    Select() {
            } 
    // page controller requires no logic
        
    }
        
        class 
    PgController {
            function 
    PgController() {
            }
            
            function 
    Fetch() {
            }
            
            function 
    Execute() {
            }
        }
        
        class 
    PgView extends BasePgView {
            function 
    PgView() {
                
    BasePgView::BasePgViewTEMPLATE_DEFAULT );
            }
            
            function 
    Render$modules ) {
                
    $count 0;
                
    $data $modules -> Fetch();
                
                foreach( 
    $data['tags'] as $tag ) {
                    
    # for every given tag to replace
                    
    $this -> Replace$tag$data[$count] );
                    
                    
    $count++;
                }
                
                
    $this -> Finalise(); 
            }
        }
        
        
    # begin application
        
    Session::Start();
        
    Page::Dispatch(); // dispatch page
        
        
    die(); 
    Looking at an earlier post from last week, cannot remember exact one sorry, but it was centred on using pre and post processing yes ?

    There was some nice idea's in the posted script which I plan to look at which might actually help improve on my own script ?

    Obviously though, this isn't pre or post processing as such. If you've any idea's of your own, I'm open to suggestions as well


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
  •