2012-03-26 2 views
0
__PACKAGE__->config(namespace => 'Hello') 

Jetzt in Betracht ziehen, ich habe obige Aussage in meinem Katalysator-Controller Hello.pm.
Dies entspricht http://localhost:3000/Hello in URL.
Aber ich möchte auch http://localhost:3000/hello übereinstimmen.Übereinstimmung Namespace Groß-und Kleinschreibung in Catalyst Controller

Ein Weg, ich versucht, dies unter

sub match_hello : Path('/hello') 
{ 
my ($self, $c) = @_; 
$c->response->body("lowercase hello also matched"); 

} 

wie zu erreichen Aber wir können auch gleiche erreichen __PACKAGE__->config(namespace => ...) Anweisung?

Antwort

0

Kein Problem mit Namespaces. Lesen Sie Action types in Catalyst::Manual::Intro.

Fügen Sie dem Stammcontroller eine LocalRegex Aktion hinzu.

sub match_hello :LocalRegex('(?i)^hello$') { 
    my ($self, $c) = @_; 
    $c->response->body('case-insensitive hello matches'); 
} 

Debug-Ausgabe:

[debug] Loaded Regex actions: 
.-------------------------------------+--------------------------------------. 
| Regex        | Private        | 
+-------------------------------------+--------------------------------------+ 
| ^(?:.*?)(?i)^hello$     | /match_hello       | 
'-------------------------------------+--------------------------------------' 

Anfrage:

$ GET http://localhost:5000/HeLlO 
case-insensitive hello matches 
+0

Ihre Lösung läuft nicht, wenn '__PACKAGE __-> config (namespace => 'Hallo');' Erklärung vorliegt Es funktioniert jedoch, wenn der Namespace leer ist, dh '__PACKAGE __-> config (Namespace => '');' Ich möchte eine Lösung mit 'Hallo' Namespace und dieses' Hallo' sollte Groß- und Kleinschreibung nicht beachten. –

+0

@ daxim- eine Änderung in Ihrer Lösung erforderlich ist 'Regex' Aktion anstelle von' LocalRegex'. Dann wird es funktionieren. Aber immer noch Es wird nur eine einzige Methode und nicht der Controller übereinstimmen. –

Verwandte Themen