Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [ZendFramework]Route po raz kolejny, help
JarCzeS
post
Post #1





Grupa: Zarejestrowani
Postów: 42
Pomógł: 0
Dołączył: 5.05.2008

Ostrzeżenie: (0%)
-----


Witam.
Zaznaczam od razu na poczatku ze dopiero zaczynam bawic sie Zend'em wiem prosze o wyrozumialosc.
Chcialbym przeksztalcic swoje adresy tj. np. page/view/id/109 na page/view/id/109.html
Probowałem troche sam poczytac ale nie moge znalezc rozwiazania stanelo na tym (wycinek mojego index.php, routery tylko tam sie definiuje?):
  1. <?php
  2. $route = new Zend_Controller_Router_Route_Regex(
  3.    'page/view/id/([0-9]).html',
  4.    array(
  5.        'controller' => 'page',
  6.        'action' => 'view'
  7.    ),
  8.    array(
  9.        1 => 'id'
  10.    )
  11. );
  12. $router->addRoute('page', $route);
  13.  
  14. // setup controller
  15. $frontController = Zend_Controller_Front::getInstance();
  16. $frontController->setRouter($router);
  17. ?>
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 18)
thm
post
Post #2





Grupa: Zarejestrowani
Postów: 52
Pomógł: 10
Dołączył: 6.10.2008
Skąd: Lublin

Ostrzeżenie: (0%)
-----


na oko:
zamień ([0-9]) na (:id)

// a jasne. głupoty opowiadam. sory

Ten post edytował thm 22.10.2008, 08:27:36
Go to the top of the page
+Quote Post
JarCzeS
post
Post #3





Grupa: Zarejestrowani
Postów: 42
Pomógł: 0
Dołączył: 5.05.2008

Ostrzeżenie: (0%)
-----


Cytat(thm @ 22.10.2008, 09:26:19 ) *
na oko:
zamień ([0-9]) na (:id)

// a jasne. głupoty opowiadam. sory


to by chyba zadzialalo przy Zend_Controller_Router_Route czy jakos tak
a ja bym chcial miec te html na koncu (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

Ten post edytował JarCzeS 22.10.2008, 08:52:56
Go to the top of the page
+Quote Post
thm
post
Post #4





Grupa: Zarejestrowani
Postów: 52
Pomógł: 10
Dołączył: 6.10.2008
Skąd: Lublin

Ostrzeżenie: (0%)
-----


trochę mnie to interesi. więc pozwolę sobie dopytać:
jakim wyjątkiem ci pluje?
Go to the top of the page
+Quote Post
JarCzeS
post
Post #5





Grupa: Zarejestrowani
Postów: 42
Pomógł: 0
Dołączył: 5.05.2008

Ostrzeżenie: (0%)
-----


Cytat(thm @ 22.10.2008, 09:59:07 ) *
trochę mnie to interesi. więc pozwolę sobie dopytać:
jakim wyjątkiem ci pluje?



[404] File Not Found : Plik nie istnieje
zarówno jak wchodze na index.php jak i na page/view/id/109.html
wydaje mi sie ze zle definuje ten router :/ to sie tylko dopisuje tylko do bootstrap'a?

Ten post edytował JarCzeS 22.10.2008, 09:13:29
Go to the top of the page
+Quote Post
thm
post
Post #6





Grupa: Zarejestrowani
Postów: 52
Pomógł: 10
Dołączył: 6.10.2008
Skąd: Lublin

Ostrzeżenie: (0%)
-----


Kod
$frontController->setRouter($router);

to jest niepotrzebne.
Go to the top of the page
+Quote Post
JarCzeS
post
Post #7





Grupa: Zarejestrowani
Postów: 42
Pomógł: 0
Dołączył: 5.05.2008

Ostrzeżenie: (0%)
-----


to samo mam 404 (IMG:http://forum.php.pl/style_emoticons/default/sad.gif)
Go to the top of the page
+Quote Post
batman
post
Post #8





Grupa: Moderatorzy
Postów: 2 921
Pomógł: 269
Dołączył: 11.08.2005
Skąd: 127.0.0.1




A nie powinno być przypadkiem tak:

'page/view/id/([0-9])\.html'

Chodzi mi o tego backslasha przed kropką.
Go to the top of the page
+Quote Post
JarCzeS
post
Post #9





Grupa: Zarejestrowani
Postów: 42
Pomógł: 0
Dołączył: 5.05.2008

Ostrzeżenie: (0%)
-----


Cytat(batman @ 22.10.2008, 11:01:17 ) *
A nie powinno być przypadkiem tak:

'page/view/id/([0-9])\.html'

Chodzi mi o tego backslasha przed kropką.


nie dziala
przy index.php dostaje:

Notice: Undefined variable: router in /home/******/index.php on line 46

Fatal error: Call to a member function addRoute() on a non-object in /home/****/index.php on line 46

a przy page/view/id/109.html

404 not found
Go to the top of the page
+Quote Post
thm
post
Post #10





Grupa: Zarejestrowani
Postów: 52
Pomógł: 10
Dołączył: 6.10.2008
Skąd: Lublin

Ostrzeżenie: (0%)
-----


nie masz instancji Routera
Kod
$router = $frontController->getRouter();
Go to the top of the page
+Quote Post
JarCzeS
post
Post #11





Grupa: Zarejestrowani
Postów: 42
Pomógł: 0
Dołączył: 5.05.2008

Ostrzeżenie: (0%)
-----


Cytat(thm @ 22.10.2008, 11:44:13 ) *
nie masz instancji Routera
Kod
$router = $frontController->getRouter();

ok index.php i stare adresy dzialaja ale moj router nie (IMG:http://forum.php.pl/style_emoticons/default/sad.gif)
page/view/id/109 - dziala
page/view/id/109.html - nie dziala

przypominam kod:

  1. <?php
  2. $route = new Zend_Controller_Router_Route_Regex(
  3.    'page/view/id/([0-9]).html',
  4.    array(
  5.        'controller' => 'page',
  6.        'action' => 'view'
  7.    ),
  8.    array(
  9.        1 => 'id'
  10.    )
  11. );
  12.  
  13.  
  14. // setup controller
  15. $frontController = Zend_Controller_Front::getInstance();
  16.  
  17. //$frontController->setRouter($router);
  18. $router = $frontController->getRouter();
  19. $router->addRoute('page', $route);
  20. ?>


Ten post edytował JarCzeS 22.10.2008, 10:55:43
Go to the top of the page
+Quote Post
nrm
post
Post #12





Grupa: Zarejestrowani
Postów: 627
Pomógł: 33
Dołączył: 1.05.2005
Skąd: Katowice

Ostrzeżenie: (0%)
-----


tak swoja drogą, obok tematu, na cholerę tak urle psujecie tymi .html ? Punktów za to od googla nie dostaniecie...
Go to the top of the page
+Quote Post
elemek
post
Post #13





Grupa: Zarejestrowani
Postów: 71
Pomógł: 24
Dołączył: 14.08.2008

Ostrzeżenie: (0%)
-----


schemat na pewno jest zły, powinien być:

Kod
page/view/id/(\d+)\.html


pozatym reszta jak w 1 poscie jest ok chociaz nie musisz tworzyc nowego rutera mozna skorzystac z domyslnego przez getInstance();

Ten post edytował elemek 22.10.2008, 18:23:48
Go to the top of the page
+Quote Post
JarCzeS
post
Post #14





Grupa: Zarejestrowani
Postów: 42
Pomógł: 0
Dołączył: 5.05.2008

Ostrzeżenie: (0%)
-----


Cytat(JarCzeS @ 22.10.2008, 20:55:00 ) *
  1. <?php
  2. $route = new Zend_Controller_Router_Route_Regex(
  3.    'page/view/id/(d+).html',
  4.    array(
  5.        'controller' => 'page',
  6.        'action' => 'view'
  7.    ),
  8.    array(
  9.        1 => 'id'
  10.    )
  11. );
  12.  
  13.  
  14. // setup controller
  15. $frontController = Zend_Controller_Front::getInstance();
  16.  
  17.  
  18. $router = $frontController->getRouter();
  19. $router->addRoute('page', $route);
  20. ?>

ma ktos jakis pomysl dlaczego to nie dziala??

Ten post edytował JarCzeS 24.10.2008, 09:45:57
Go to the top of the page
+Quote Post
eai
post
Post #15





Grupa: Zarejestrowani
Postów: 367
Pomógł: 10
Dołączył: 20.05.2005

Ostrzeżenie: (0%)
-----


zamiast: 'page/view/id/(d+).html',

daj 'page/view/id/(d+)\.html',

. - w wyrażeniu regularnym oznacza jakikolwiek znak
natomiast \. - to poprostu zwykła kropka (poprzez backslash usuwamy znaczenie specjalne)

Zainteresuj się też: http://pl.php.net/manual/pl/function.quotemeta.php
Go to the top of the page
+Quote Post
JarCzeS
post
Post #16





Grupa: Zarejestrowani
Postów: 42
Pomógł: 0
Dołączył: 5.05.2008

Ostrzeżenie: (0%)
-----


Cytat(eai @ 25.10.2008, 11:52:09 ) *
zamiast: 'page/view/id/(d+).html',

daj 'page/view/id/(d+)\.html',

. - w wyrażeniu regularnym oznacza jakikolwiek znak
natomiast \. - to poprostu zwykła kropka (poprzez backslash usuwamy znaczenie specjalne)

Zainteresuj się też: http://pl.php.net/manual/pl/function.quotemeta.php

  1. <?php
  2. $route = new Zend_Controller_Router_Route_Regex(
  3.   'page/view/id/(d+).html',
  4.   array(
  5.       'controller' => 'page',
  6.       'action' => 'view'
  7.   ),
  8.   array(
  9.       1 => 'id'
  10.   )
  11. );
  12.  
  13.  
  14. // setup controller
  15. $frontController = Zend_Controller_Front::getInstance();
  16.  
  17.  
  18. $router = $frontController->getRouter();
  19. //$frontController->setRouter($router);
  20. $router->addRoute('page', $route);
  21. ?>

page/view/id/110 - dziala
adres page/view/id/110.html nie dziala (IMG:http://forum.php.pl/style_emoticons/default/sad.gif)
Go to the top of the page
+Quote Post
Martio
post
Post #17





Grupa: Zablokowani
Postów: 167
Pomógł: 2
Dołączył: 15.02.2004

Ostrzeżenie: (30%)
XX---


Akurat siedzę nad pewnym projektem pod ZF i wrzuciłem sobie definicję tej trasy rutera i jest OK. Zerknij w kod, bo ta regułka działa. Może zdefiniuj sobie pod projekt wirtualkę jak nie masz i ponownie spróbuj: http://projekt-name/page/view/id/110.html
Go to the top of the page
+Quote Post
JarCzeS
post
Post #18





Grupa: Zarejestrowani
Postów: 42
Pomógł: 0
Dołączył: 5.05.2008

Ostrzeżenie: (0%)
-----


Cytat(Martio @ 28.10.2008, 13:20:00 ) *
Akurat siedzę nad pewnym projektem pod ZF i wrzuciłem sobie definicję tej trasy rutera i jest OK. Zerknij w kod, bo ta regułka działa. Może zdefiniuj sobie pod projekt wirtualkę jak nie masz i ponownie spróbuj: http://projekt-name/page/view/id/110.html


to mzoe mam cos nie tak w htaccess?
Kod
RewriteEngine on
  RewriteRule !\.(htm|html|txt|swf|js|ico|gif|jpg|png|css|php|xml)$ index.php
  
  
  
  php_flag register_globals off

usunolem z htaccess htm i html i dziala
dziekuje wszystkim za pomoc

Ten post edytował JarCzeS 29.10.2008, 10:29:09
Go to the top of the page
+Quote Post
orideith
post
Post #19





Grupa: Zarejestrowani
Postów: 72
Pomógł: 1
Dołączył: 21.07.2006

Ostrzeżenie: (0%)
-----


Rozwiązanie podobne zamieściłem na stronie zf-pl
http://forum.zend-framework.pl/viewtopic.php?id=396

(na samym dole końcowe rozwiązanie)
Pozdrawiam

Ten post edytował orideith 7.11.2008, 13:08:14
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 23.08.2025 - 17:02