Yaf_Route_Rewrite::__construct

(Yaf >=1.0.0)

Yaf_Route_Rewrite::__constructYaf_Route_Rewrite constructor

Beschreibung

public Yaf_Route_Rewrite::__construct(string $match, array $route, array $verify = ?)

Parameter-Liste

match

A pattern, will be used to match a request uri, if it doesn't match, Yaf_Route_Rewrite will return false.

You can use :name style to name segments matched, and use * to match the rest of the URL segments.

route

When the match pattern matches the request uri, Yaf_Route_Rewrite will use this to decide which module/controller/action is the destination.

Either of module/controller/action in this array is optional, if you don't assign a specific value, it will be routed to default.

verify

Rückgabewerte

Beispiele

Beispiel #1 Yaf_Route_Rewrite()example

<?php
   
/**
    * Add a rewrite route to Yaf_Router route stack
    */
    
Yaf_Dispatcher::getInstance()->getRouter()->addRoute("name",
        new 
Yaf_Route_rewrite(
           
"/product/:name/:id/*"//match request uri leading "/product"
           
array(
               
'controller' => "product",  //route to product controller,
           
),
        )
    );
?>

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:

/* for http://yourdomain.com/product/foo/22/foo/bar
 * route will result in following values:
 */
array(
  "controller" => "product",
  "module"     => "index", //(default)
  "action"     => "index", //(default)
)

/**
 * and request parameters:
 */
array(
  "name" => "foo",
  "id"   => 22,
  "foo"  => bar
)

Beispiel #2 Yaf_Route_Rewrite()example

<?php
   
/**
    * Add a rewrite route to Yaf_Router route stack by calling addconfig
    */
    
$config = array(
        
"name" => array(
           
"type"  => "rewrite",        //Yaf_Route_Rewrite route
           
"match" => "/user-list/:id"//match only /user/list/?/
           
"route" => array(
               
'controller' => "user",  //route to user controller,
               
'action'     => "list",  //route to list action
           
),
        ),
    );
    
Yaf_Dispatcher::getInstance()->getRouter()->addConfig(
        new 
Yaf_Config_Simple($config));
?>

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:

/* for http://yourdomain.com/user-list/22
 * route will result in following values:
 */
array(
  "controller" => "user",
  "action"     => "list",
  "module"     => "index", //(default)
)

/**
 * and request parameters:
 */
array(
  "id"   => 22,
)

Beispiel #3 Yaf_Route_Rewrite(as of 2.3.0)()example

<?php
   
/**
    * Add a rewrite route use match result as m/c/a name
    */
    
$config = array(
        
"name" => array(
           
"type"  => "rewrite",        
           
"match" => "/user-list/:a/:id"//match only /user-list/*
           
"route" => array(
               
'controller' => "user",   //route to user controller,
               
'action'     => ":a",     //route to :a action
           
),
        ),
    );
    
Yaf_Dispatcher::getInstance()->getRouter()->addConfig(
        new 
Yaf_Config_Simple($config));
?>

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:

/* for http://yourdomain.com/user-list/list/22
 * route will result in following values:
 */
array(
  "controller" => "user",
  "action"     => "list",
  "module"     => "index", //(default)
)

/**
 * and request parameters:
 */
array(
  "id"   => 22,
)

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.

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

Definition von Stored Procedures - eine Einführung

Stored Procedures sind vordefinierte SQL-Codeblöcke, die in einer Datenbank gespeichert sind und bei Bedarf aufgerufen werden können. ...

Bernie

Autor : ebiz-consult GmbH & Co. KG
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

Ich bin am verrückt werden - Session und neue Webseite

That is an extremely bright idea

Geschrieben von EssaMattou am 02.05.2024 09:34:57
Forum: SQL / Datenbanken
"Why adore HTMX over JavaScript?"

What specific features or aspects of HTMX, a library designed to enhance interactions in web applications, appeal to users who have a strong affin ...

Geschrieben von WartanThamar am 02.05.2024 06:53:08
Forum: HTML, JavaScript, AJAX, jQuery, CSS, Bootstrap, LESS
What defines Laravel's developer community?

What factors contribute to the perceived happiness within the Laravel developer community, and how does this compare to other developer communitie ...

Geschrieben von BakhamMamodar am 01.05.2024 10:45:23
Forum: PHP Developer Forum