php - How to fix ? on the link instead of / -


i want link 'name' other page '/nameid'.

for example: <a href='./2'>number 2</a>

i have tried:

@foreach($adverts $advert)    {{link_to_route('adverts', $advert->name, array($advert->id))}}  @endforeah 

it returns me: <a href="http://localhost:8000/?2">, need <a href="http://localhost:8000/2">.

where wrong?

more details:

models/advert.php

class advert extends eloquent {     protected $table = 'adverts'; } 

routes.php

route::get('/', array('as'=>'adverts', 'uses'=>'advertscontroller@index')); route::get('/{id}', array('as'=>'advert', 'uses'=>'advertscontroller@info')); 

controllers/advertscontroller.php

public function index() {     return view::make('adverts.index')                ->with('adverts', advert::all()); } public function info($id) {     return view::make('adverts.info')                ->with('advert', advert::find($id)); } 

when change second route 'as'=>'adverts' works fine. have no idea why works. if understand clearly, 'as'=>'advert' specific name of route, isn’t it?

you’re using wrong route. should using advert (singular), that’s route takes parameter. if try , use index route (adverts), it’ll tack additional parameters on query string.

so given have these routes:

route::get('/', array('as'=>'adverts', 'uses'=>'advertscontroller@index')); route::get('/{id}', array('as'=>'advert', 'uses'=>'advertscontroller@info')); 

if want link individual advert, need use this:

{{ link_to_route('advert', $advert->name, array($advert->id)) }} 

also, may want take @ resource controllers. they’re perfect situations these, want 1 route/view list resource, , route/view view details of particular resource.


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -