Yaf_Route_Regex::__construct

(Yaf >=1.0.0)

Yaf_Route_Regex::__constructYaf_Route_Regex constructor

Beschreibung

public Yaf_Route_Regex::__construct(
    string $match,
    array $route,
    array $map = ?,
    array $verify = ?,
    string $reverse = ?
)

Parameter-Liste

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().

Hinweis:

this parameter is introduced in 2.3.0

Rückgabewerte

Beispiele

Beispiel #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.
           
)
        )
    );
?>

Beispiel #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.
           
)
        )
    );
?>

Beispiel #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.
           
)
        )
    );
?>

Beispiel #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));
?>

Siehe auch

Hier Kannst Du einen Kommentar verfassen


Bitte gib mindestens 10 Zeichen ein.
Wird geladen... Bitte warte.
* Pflichtangabe
Es sind noch keine Kommentare vorhanden.

PHP cURL-Tutorial: Verwendung von cURL zum Durchführen von HTTP-Anfragen

cURL ist eine leistungsstarke PHP-Erweiterung, die es Ihnen ermöglicht, mit verschiedenen Servern über verschiedene Protokolle wie HTTP, HTTPS, FTP und mehr zu kommunizieren. ...

TheMax

Autor : TheMax
Kategorie: PHP-Tutorials

Midjourney Tutorial - Anleitung für Anfänger

Über Midjourney, dem Tool zur Erstellung digitaler Bilder mithilfe von künstlicher Intelligenz, gibt es ein informatives Video mit dem Titel "Midjourney Tutorial auf Deutsch - Anleitung für Anfänger" ...

Mike94

Autor : Mike94
Kategorie: KI Tutorials

Grundlagen von Views in MySQL

Views in einer MySQL-Datenbank bieten die Möglichkeit, eine virtuelle Tabelle basierend auf dem Ergebnis einer SQL-Abfrage zu erstellen. ...

admin

Autor : admin
Kategorie: mySQL-Tutorials

Tutorial veröffentlichen

Tutorial veröffentlichen

Teile Dein Wissen mit anderen Entwicklern weltweit

Du bist Profi in deinem Bereich und möchtest dein Wissen teilen, dann melde dich jetzt an und teile es mit unserer PHP-Community

mehr erfahren

Tutorial veröffentlichen

Daten einer Abfrage mit Hilfe von Thumbnails nebeneinander ausgeben

Warum soll ich float meiden? Siehe https://www.linkedin.com/pulse/css-float-vs-grid-flexbox-sachin-tiwari Falls es mit Englisch nicht so klappt: ...

Geschrieben von scatello am 18.05.2024 05:57:56
Forum: PHP Developer Forum
Daten einer Abfrage mit Hilfe von Thumbnails nebeneinander ausgeben

Also den Fehler habe ich gefunden und abgestellt. Warum soll ich float meiden?

Geschrieben von Malchor am 17.05.2024 20:54:01
Forum: PHP Developer Forum
Daten einer Abfrage mit Hilfe von Thumbnails nebeneinander ausgeben

Dein HTML-Code ist definitiv kaputt und float solltest du auch vergessen. Beschäftige dich mit Flex-Box oder Grid

Geschrieben von scatello am 17.05.2024 20:43:50
Forum: PHP Developer Forum
Daten einer Abfrage mit Hilfe von Thumbnails nebeneinander ausgeben

Da ich viele unterschiedliche Tabellen benötige mache ich das so umständlich. Aber ist das der Grund warum das Floaten nicht funktioniert?

Geschrieben von Malchor am 17.05.2024 17:15:03
Forum: PHP Developer Forum