Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [CI] przekierowanie kontroler/id
dżozef
post 8.07.2013, 16:26:07
Post #1





Grupa: Zarejestrowani
Postów: 125
Pomógł: 9
Dołączył: 25.05.2013

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


Nie działa mi przekierowanie http://example.com/registrars/1 i nie wiem dlaczego:

config/routes.php:
  1. $route['registrars'] = 'registrars';
  2. $route['registrars/:num'] = 'registrars';


controllers/registrars.php:
  1. public function index($id=0)
  2. {
  3. $this->load->model('registrars_model');
  4. $this->load->model('domains_model');
  5.  
  6. $data['title'] = 'Registrars';
  7. $data['description'] = 'Browse and update your registrars, see the number of domains you have with each of them.';
  8.  
  9. if ($id==0) {
  10. $this->load->view('registrars_view', $data);
  11. }
  12. else {
  13. $data['id'] = $id;
  14. $this->load->view('single_reg_view', $data);
  15. }
  16. }


działa bez podania id, czyli http://example.com/registrars
ale - co dziwne - działa gdy zdubluję i podam tak: http://dev/ci/index.php/registrars/registrars/1

podejrzewam, że route jest źle skonfigurowane, poratuje ktoś pomocną CI-dłonią?


--------------------
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 4)
tabbi
post 8.07.2013, 16:50:31
Post #2





Grupa: Zarejestrowani
Postów: 150
Pomógł: 3
Dołączył: 30.10.2010

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


$route['registrars/(:num)'] = "registrars/index/$1";

Link: http://ellislab.com/codeigniter/user-guide...al/routing.html
Go to the top of the page
+Quote Post
dżozef
post 8.07.2013, 16:54:45
Post #3





Grupa: Zarejestrowani
Postów: 125
Pomógł: 9
Dołączył: 25.05.2013

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


w takim razie jak przerobić tego route żeby działało z registrars/1 ?


--------------------
Go to the top of the page
+Quote Post
tabbi
post 8.07.2013, 17:03:17
Post #4





Grupa: Zarejestrowani
Postów: 150
Pomógł: 3
Dołączył: 30.10.2010

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


Nie rozumiem pytania ?

  1. $route['registrars/(:num)'] = "registrars/index/$1";


metoda powinna mapować drugi segment

  1. public function index()
  2. {
  3. $id = (int) $this->uri->segment(2);
  4. $this->load->model('registrars_model');
  5. $this->load->model('domains_model');
  6.  
  7. $data['title'] = 'Registrars';
  8. $data['description'] = 'Browse and update your registrars, see the number of domains you have with each of them.';
  9.  
  10. if ($id==0) {
  11. $this->load->view('registrars_view', $data);
  12. }
  13. else {
  14. $data['id'] = $id;
  15. $this->load->view('single_reg_view', $data);
  16. }
  17. }


i wtedy każde przekierowanie registrars/4 -> registrars/index/4 gdzie w metodzie index 4 jest odbierana jako 2 segment

Ten post edytował tabbi 8.07.2013, 17:04:44
Go to the top of the page
+Quote Post
dżozef
post 8.07.2013, 17:08:09
Post #5





Grupa: Zarejestrowani
Postów: 125
Pomógł: 9
Dołączył: 25.05.2013

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


aj, nie skumałem za pierwszym razem. wielkie dzięki, już działa


--------------------
Go to the top of the page
+Quote Post

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

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 04:03