user1906399
user1906399

Reputation: 771

passing parameter via url in Laravel4 is not working

It is possible to pass parameter to the page using controller via ->with() for example

public function two(){

 return View::make('page2')->with('id', 2);

}

and now $id can be accessible in page2.blade.php

But i want to pass parameters via url with array like the way below

routes.php

<?php
Route::get('page1', 
array(
'uses' => 'pagecontroller@page1'

));

Route::get('page2/{$id}',
 array(
 'uses'=>'pagecontroller@page2'
 ));

pagecontroller.php

<?php

class pagecontroller extends BaseController{


  public function page1(){

   return View::make('page1');

  }

  public function page2($id){

    return "ID : $id";

  }

page1.blade.php

<p>This Is Page1</p>

<a href="{{action('pagecontroller@page2', array('id'=>1)  )}}">Page2</a>

And it is showing the error : Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException

Where is it going wrong?

Upvotes: 0

Views: 128

Answers (1)

Gadoma
Gadoma

Reputation: 6565

You have a little typo in your routes. The parameter is defined without the "$" prefix.

Route::get('page2/{$id}',

should be

Route::get('page2/{id}',

Remember to do composer dump-autoload after you change your routes.php file.

You might want to take a moment and check out the docs on routing params http://laravel.com/docs/routing#route-parameters

Upvotes: 1

Related Questions