Thursday, 15 September 2011

php - How to do nice GET URLs in Laravel -



php - How to do nice GET URLs in Laravel -

if have form:

<form method="get" action="<?=action( "somethingcontroller@dosomething" ) )?>"> <select name="somethingid"> <?php foreach( $somethings $something ) : ?> <option value="<?=$something->id?>"><?=$something->title?></option> <?php endforeach; ?> </select> </form>

how do route dosomething function gets id given rather generating ugly hell url www.example.com/project/3/something?somethingid=7

route::get( "project/3/something/{somethingid}", "somethingcontroller@dosomething", function( $somethingid ) { homecoming app::make( "somethingcontroller" )->dosomething( $somethingid ); } );

i want url www.example.com/project/3/something/7

the problem can't post... because people can never go url... they'd have post it.

do need create dropdown box alter anchor href of button javascript generates right url that?

can't seem find in here: http://laravel.com/docs/4.2/routing

i sense you're doing right... little confused on you're trying though, , subsequently doing "wrong" (since seems right), apologies in advance shot in dark. instead of select, can utilize simple tags?

@foreach($somethings $something) <a href="{{ url::to('3/something/'.$something->id) }} ">{{ $something->title }}</a> @endforeach

that way, clicking link takes them www.example.com/project/3/something/7 -> or whatever id generated link. routing, do:

route::get("project/3/something/{somethingid}", "somethingcontroller@getsomething"); route::post("project/3/something/{somethingid}", "somethingcontroller@postsomething");

and controller:

public function getsomething($somethingid){ // handle returning view , whatever else need } public function postsomething($somethingid){ // handle post function (i.e. stuff.) }

those couple things seek when routing dependent on variable id's, if there's else you're trying accomplish, leave comment , i'll well.

cheers!

php laravel routing

No comments:

Post a Comment