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
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:

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

I get:

Array ( [data] => exxdataaa ) 

exxxdataaa is the what match with :variable section.

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.