Page Routing - ZingPHP/Zing GitHub Wiki

Page Routing allows you to build custom paths to pages this is helpful when you don't want/need to use the default route provided by Zing. By default zing uses Page/Action to access a page, where Page is the class name and Action is the method name.

Here is an example of a config with a few routes set.

A few things to note:

  • @ means a string of anything
  • # means a numeric string

Note: Both @ and # will be converted to $_GET variables.

$config = array(
    "websites"  => array(
        array(
            "host"   => "example.com",
            "routes" => array(
                "/ajax/@page/@action",               // @action and @page come from the url
                "/@page=actor/@name",                // @action defaults to main when @page equals actor
                "/@page=movie/#id @action=movieItem" // @action defaults to movieItem when @page equals movie followed by a number
            )
        )
    )
);
  • The first route in list says: "This is how I want ajax urls to look". Note: By default Zing knows that anything that starts with /ajax is an ajax request and will not use Smarty templates in the return result.
  • The second route in the list says: "This is how I want urls to look when the page equals actor".
  • The last route is similar to the second route, the difference is, is that it has a space in it. Everything after the space are defaults to be set (comma separated).

There is one more type of routing, and that is permanent routing. This overrides all other routes, and is good for bringing the site down for maintenance, or a "Coming Soon" page.

$config = array(
    "websites"  => array(
        array(
            "host"   => "example.com",
            "route" => array(
                "page" => "comingSoon"
                "action" => "I_Am_Optional"
            )
        )
    ),
);

Now no matter what page someone goes to they will be redirected to the "Coming Soon" page. Or if this was a maintenance page, they would then be redirected there.