SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2010
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I think I need some help for creating my own router

    May you see CleanMVC. That is the MVC that I created before 1-2 weeks.
    Now I'm trying to create a router for CleanMVC.

    Here is the router class that doesn't run yet.

    And using of router is below:
    PHP Code:
    <?php
    require_once '../library/router.php';
    $router = new router();

    $router->add(array('controller'=>':example''-''function'=>'saffet''-''data'=> ':variable' ,'.html'), function(){
        echo 
    'just try';
    });

    $router->submit();
    ?>
    I'm still getting url as /controller/function/data. This must run as example-saffet-$1.html. In a sense, if url will be example-saffet-exdataaa.html it must run like /example/saffet/exdataaaa. But this is just an example user will can create url whatever they want.

    I wish I can tell. My purpose is creating a router like codeigniter's..

    EDIT:

    Now, when I add this:
    PHP Code:
    $router->add(array('controller'=>'example''-''function'=>'saffet''-''data'=> ':variable' ,'.html'), function(){
        echo 
    'just try';
    }); 
    I get:
    Code:
    Array ( [data] => exxdataaa )
    exxxdataaa is the what match with :variable section.

  2. #2
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,412
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    Hi Derpost,

    I had a look at your router class, but I found it difficult to follow the logic in the submit method so I thought I'd rewrite it to try and understand how it works. I ended up refactoring the whole class just as an exercise.. my version is at https://gist.github.com/LordZicon/3fa7cfdb47f84ec30068.

    You're welcome to use any of the code if helps at all, and If you've got any questions feel free to ask.


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
  •