SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    FreeBSD The Power to Serve silver trophy pippo's Avatar
    Join Date
    Jul 2001
    Location
    Italy
    Posts
    4,514
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Multi lingual pages oop

    Hi,
    I was trying to develop my bi-lingual web site using some ideas I had from guys here at sitepoint.
    I see that recently these arguments are well discussed here,
    so I hope I will not ask for something already discussed.

    I think that the below code should explain itself,
    I'm looking for hints and suggestions!

    Thank you!

    pippo

    /*
    ** Every request is internally redirected here by mr. apache!
    ** So requests of /it/article, or /en/article, or /it/article/333
    ** will be redirected by mr. apache to main.php
    ** No arguments are passed to main.php because the REQUEST_URI var
    ** is used instead.
    */
    main.php
    PHP Code:
    <?php
    require_once 'app.inc.php';

    App::Run();
    ?>
    app.inc.php
    PHP Code:
    <?php
    /*
     ** Class Name : App
     ** Description:
    */
    class App
    {
        
    /*
         ** Function Name: Run
         ** Parameters   : none
         ** Return       : none
         ** Description  :
        */
        
    function Run()
        {
            require_once 
    'page_viewer.inc.php';

            
    /*
             ** Explanation:
             ** The url will be something like:
             ** /it/article, for articles list in italian
             ** /en/article, for articles list in english
             **
             ** /it/article/333, for article 333 in italian
             **
             ** etc
            */
            
    PageViewer::Showexplode"\\"$_REQUEST_URI ) );
        }
    }
    ?>
    page_viewer.inc.php
    PHP Code:
    <?php
    /*
     ** Class Name : PageViewer
     ** Description:
    */
    class PageViewer
    {
        
    /*
         ** Function Name: Show
         ** Parameters   : none
         ** Return       : none
         ** Description  :
        */
        
    function Show$url_arg )
        {
            if ( !isset(
    $url_arg] ) )
            {
                
    /* Set default language */
                
    $url_arg] = 'it';
            }

            
    /* Check page name */
            
    switch ( $url_arg] )
            {
                case 
    'article':
                    if ( isset( 
    $url_arg] ) )
                    {
                        require_once 
    'page_article.inc.php';

                        
    $page = new PageArticle$url_arg], $url_arg] );
                        break;
                    }
                    require_once 
    'page_articlelist.inc.php';

                    
    $page = new PageArticleList$url_arg] );
                    break;

                default:
                    require_once 
    'page_default.inc.php';

                    
    $page = new PageDefault();
                    break;
            }

            
    $page->Show();
        }
    }
    ?>
    page_article.inc.php
    PHP Code:
    <?php
    require_once 'page.inc.php';

    /*
     ** Class Name : PageArticle
     ** Description:
    */
    class PageArticle extend Page
    {
        var 
    $lang;
        var 
    $id;

        
    /*
         ** Function Name: PageArticle
         ** Parameters   : none
         ** Return       : none
         ** Description  :
        */
        
    function PageArticle$lang$id )
        {
            
    $this->lang $lang;
            
    $this->id   $id;
        }

        
    /*
         ** Function Name: Show
         ** Parameters   : none
         ** Return       : none
         ** Description  :
        */
        
    function Show()
        {
            
    $this->ShowHeader();
            
    // article content
            
    $this->ShowFooter();
        }
    }
    ?>
    page.inc.php
    PHP Code:
    <?php
    /*
     ** Class Name :Page
     ** Description:
    */
    class Page
    {
        
    /*
         ** Function Name: Page
         ** Parameters   : none
         ** Return       : none
         ** Description  :
        */
        
    function Page()
        {
        }

        
    /*
         ** Function Name: ShowHeader
         ** Parameters   : none
         ** Return       : none
         ** Description  :
        */
        
    function ShowHeader()
        {
        }

        
    /*
         ** Function Name: ShowFooter
         ** Parameters   : none
         ** Return       : none
         ** Description  :
        */
        
    function ShowFooter()
        {
        }
    }
    ?>
    Last edited by pippo; Sep 2, 2002 at 06:18.
    Mr Andrea
    Former Hosting Team Advisor
    Former Advisor of '03

  2. #2
    SitePoint Evangelist
    Join Date
    Oct 2001
    Posts
    592
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Some points:

    - Class App is a static class, having only one (static) method. This method in turn holds only one line of code. So: should class App really exist?
    - explode( "\", $_REQUEST_URI ) should probably be explode('/', $_SERVER['REQUEST_URI'])
    - I have some idea that this:
    PHP Code:
    if ( !isset($url_arg] ) ) 

        
    $url_arg] = 'it'

    switch ( 
    $url_arg] ) 
    ...is logically incorrect. (If $arg[0] isn't set, then $arg[1] certainly won't be set!)
    - Class PageViewer calls the method Show on some subclass of class Page (way to go!). However, class Page doesn't define the method Show itself. For clean and correct OO, you might want to add it.

    All in all I think it's a nice, simple and clean piece of code. But then, the design is somehow a bit familiar...

    Vincent
    Last edited by voostind; Sep 2, 2002 at 08:43.

  3. #3
    FreeBSD The Power to Serve silver trophy pippo's Avatar
    Join Date
    Jul 2001
    Location
    Italy
    Posts
    4,514
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    >>should class App really exist?
    Maybe no, the body of main.php is really App::Run.

    >>should probably be explode('/', $_SERVER['REQUEST_URI'])
    Ooopss.

    >>...is logically incorrect
    Right, I have forgotten to include the code for the home page ( where $url[ 1 ] is not set ).

    >>For clean and correct OO, you might want to add it.
    That's right.

    >>But then, the design is somehow a bit familiar
    Well, you are an inspiration muse...

    Thanks a lot for the hints!


    pippo
    // Andrea
    Mr Andrea
    Former Hosting Team Advisor
    Former Advisor of '03


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
  •