Rechercher une fonction PHP

Yaf_Route_Regex::__construct

(Yaf >=1.0.0)

Yaf_Route_Regex::__constructYaf_Route_Regex constructor

Description

public Yaf_Route_Regex::__construct ( string $match , array $route [, array $map [, array $verify [, string $reverse ]]] )

PHP: Yaf_Route_Regex::__construct - Manual Home of Manuel PHP  Contents Haut

Parameters

match

A complete Regex pattern, will be used to match a request uri, if doesn't matched, Yaf_Route_Regex will return FALSE.

route

When the match pattern matches the request uri, Yaf_Route_Regex will use this to decide which m/c/a to routed.

either of m/c/a in this array is optianl, if you don't assgian a specific value, it will be routed to default.

map

A array to assign name to the captrues in the match result.

verify

reverse

a string, used to assemble url, see Yaf_Route_Regex::assemble().

Note:

this parameter is introduced in 2.3.0

PHP: Yaf_Route_Regex::__construct - Manual Home of Manuel PHP  Contents Haut

Examples

Example #1 Yaf_Route_Regex()example

<?php
   
/**
    * Add a regex route to Yaf_Router route stack
    */
    
Yaf_Dispatcher::getInstance()->getRouter()->addRoute("name",
        new 
Yaf_Route_Regex(
           
"#^/product/([^/]+)/([^/])+#"//match request uri leading "/product"
           
array(
               
'controller' => "product",  //route to product controller,
           
),
           array(
              
=> "name",   // now you can call $request->getParam("name")
              
=> "id",     // to get the first captrue in the match pattern.
           
)
        )
    );
?>

Example #2 Yaf_Route_Regex(as of 2.3.0)()example

<?php
   
/**
    * Use match result as MVC name
    */
    
Yaf_Dispatcher::getInstance()->getRouter()->addRoute("name",
        new 
Yaf_Route_Regex(
           
"#^/product/([^/]+)/([^/])+#i"//match request uri leading "/product"
           
array(
              
'controller' => ":name"// route to :name, which is $1 in the match result as controller name
           
),
           array(
              
=> "name",   // now you can call $request->getParam("name")
              
=> "id",     // to get the first captrue in the match pattern.
           
)
        )
    );
?>

Example #3 Yaf_Route_Regex and named capture ground(as of 2.3.0)()example

<?php
   
/**
    * Use match result as MVC name
    */
    
Yaf_Dispatcher::getInstance()->getRouter()->addRoute("name",
        new 
Yaf_Route_Regex(
           
"#^/product/(?<name>[^/]+)/([^/])+#i"//match request uri leading "/product"
           
array(
           
'controller' => ":name"// route to :name,
                                    // which is named capture group 'name' in the match result as controller name
           
),
           array(
              
=> "id",     // to get the first captrue in the match pattern.
           
)
        )
    );
?>

Example #4 Yaf_Route_Regex()example

<?php
   
/**
    * Add a regex route to Yaf_Router route stack by calling addconfig
    */
    
$config = array(
        
"name" => array(
           
"type"  => "regex",          //Yaf_Route_Regex route
           
"match" => "#(.*)#",         //match arbitrary request uri
           
"route" => array(
               
'controller' => "product",  //route to product controller,
               
'action'     => "dummy",    //route to dummy action
           
),
           
"map" => array(
              
=> "uri",   // now you can call $request->getParam("uri")
           
),
        ),
    );
    
Yaf_Dispatcher::getInstance()->getRouter()->addConfig(
        new 
Yaf_Config_Simple($config));
?>
Find a PHP function

English translation

You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.

If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.

Thank you in advance.

Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-yaf-route-regex.construct.html

The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.

References

  1. View the html document Language of the document:fr Manuel PHP : http://php.net

These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.

Contents Haut