SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What technique and approach should i use?

    I have built a few projects before and without any template-engine or nothing just a mix of everything and it's a pain in the *** to update and extend. So now when I'm starting my new project I'm going to build everything up so it's scale able and easy to maintain.

    I have done some research on front controllers, application controllers, mvc, framework, patterns, template views etc and it's a jungle to find something that will suit me.

    How i would like the project to look like:

    Template files with the HTML code
    Some kind of controller i guess that will handle all requests i would like not to have a php-file for every template file but i also don't want a front controller with a lot of overhead.

    I'm thinking of some kind of module like system
    user is requesting product?id=1 then the controller would load up the product template and in the template find <show:product request="id"> load up the show module and pass the query to that module and then return the results.
    The pros with this solution would be that you could create new templates without the need to create a new php file to handle the template unless you need a new module. Is this a bad idea?

    I may be way of, but you'll have to agree that it's virtually impossible to understand and find good solutions. I have read so many pages and different patterns and approaches that i have a headache. I would really appreciate if someone could take the time to help me find a good way to structure my next projects. And maybe lead me on my way to a new way of thinking when developing :)
    Last edited by thenewbie; Nov 15, 2005 at 10:48.

  2. #2
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by thenewbie
    ... i would like not to have a php-file for every template file but i also don't want a front controller with a lot of overhead.

    I'm thinking of some kind of module like system
    user is requesting product?id=1 then the controller would load up the product template and in the template find <showroduct request="id"> load up the show module and pass the query to that module and then return the results.
    The pros with this solution would be that you could create new templates without the need to create a new php file to handle the template unless you need a new module. Is this a bad idea?
    It sounds like dispatcherview (aka serverpage). I don't think you should go that way - it's basically no different from not having a system, only you are aware of it. (which ofcourse may be a plus in itself). I think that most people (myself inclusive) at first finds it needless and cumbersome to create both a controller and a template for each view - even the simpler ones. My experience however is that you might aswell go that way from the start - it will pay of later. And after all it isn't that much work to create two files rather than one - you can name them accordingly, so you can easy find out which matches which.


    Quote Originally Posted by thenewbie
    ... but i also don't want a front controller with a lot of overhead.
    I'm curious as to what kind of "overhead" you're talking about ? If it's performance, then you're definately on the wrong track. The frontcontroller can be very simple and lean, and compared to the rest of your application it matters nothing at all.

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kyberfabrikken
    It sounds like dispatcherview (aka serverpage). I don't think you should go that way - it's basically no different from not having a system, only you are aware of it. (which ofcourse may be a plus in itself). I think that most people (myself inclusive) at first finds it needless and cumbersome to create both a controller and a template for each view - even the simpler ones. My experience however is that you might aswell go that way from the start - it will pay of later. And after all it isn't that much work to create two files rather than one - you can name them accordingly, so you can easy find out which matches which.
    The reason i don't want a php-file for every template is that in the adminsystem you should be able to add pages easy, for example press add page enter <show:product id="22"> save page, make a link to it from another page <a href>Have a look at this amazing product</a>. If i would have to have a php-file for that the creator of the new page would have to contact me to do a php-page for it and upload.


    Quote Originally Posted by kyberfabrikken
    I'm curious as to what kind of "overhead" you're talking about ? If it's performance, then you're definately on the wrong track. The frontcontroller can be very simple and lean, and compared to the rest of your application it matters nothing at all.
    I have read about many front controllers with a lot of overhead, yes i know it CAN be very simple but i would need help on how to do it :)

  4. #4
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by thenewbie
    The reason i don't want a php-file for every template is that in the adminsystem you should be able to add pages easy, for example press add page enter <showroduct id="22"> save page, make a link to it from another page <a href>Have a look at this amazing product</a>.
    If you're creating pages automatically, where's the difference between creating one serverpage, or creating two (controller + template) ?
    Either way, the problem might be that you're focusing on the wrong place. A page (as percieved by the user) needn't nescesarily correspond to a single controller on the server. Multiple pages may map to the same controller, with a single parameter to select the proper data. That's where the frontcontroller fits in. Eg :
    PHP Code:
    // index.php
    class FrontController
    {
        var 
    $map = Array(
            
    'default' => 'default.php',
            
    'article' => 'article.php',
        );
        function 
    execute() {
            
    $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'default';
            if (isset(
    $this->map[$action])) {
                require_once(
    $this->map[$action]);
                
    $controllerName $action.'Controller';
                
    $controller =& new $controllerName();
                
    $controller->execute();
            } else {
                
    header("HTTP/1.0 404 Not Found");
                exit;
            }
        }
    }

    ...

    //article.php
    class ArticleController
    {
        function 
    execute() {
            
    $db =& Database::GetInstance();
            
    $result $db->query("SELECT * FROM articles WHERE id='".$db->escapeString($_REQUEST['id'])."'");
            
    $article $result->current();
            
    $t = new Template("article.tmpl");
            
    $t->set('article'$article);
            echo 
    $t->render();
        }


  5. #5
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you misunderstod me, the only time i would need to create a php-file would be if new modules are needed, i could create templates which uses modules already written.
    For example the <show> if show is a module i could create as many pages i want that accesses the show module without the need to write any php-files.

  6. #6
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What im truly after is to have different templates for one page and that can't be done via css the way i want it.


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
  •