I am new at laravel and i am using the follow syntax to call the controller directly from the url. Now I dont know how to pass the argument in these link. Please needed your help for these.
Route::get('/pagelink', 'YourController#callMeDirectlyFromUrl');
And in the link i have written these:
Link name/Embedded Button
Now how to pass the id in these code.
you can do it like this :
Route::get('/pagelink/{id}', 'YourController#callMeDirectlyFromUrl');
Link name/Embedded Button
Related
My controller posts a form to create a new page. After posting the form I need to redirect the user to the new page that will have the contents for that page that were entered in the previous form. If I simply do return view('mynewpageview', compact('mycontent')); where my mycontent is the object used to execute the $mycontent->save(); command, I carry the risk for someone refreshing the url thus posting the same content twice by creating a new page.
Instead I would like to redirect the user to the actual page url.
My route is
Route::get('/newpage/{id}', 'PageController#pagebyid'); and if I use return redirect()->route('/newpage/$pageid'); where $pageid = $mycontent->id; I get Route not defined error.
What would be the solution either to stop someone from resubmitting the content or a correct syntax for passing the parameter?
The correct answer that works for me is -
Give your route a name in the routes file
Then pass the parameters with an array as shown below in the controller.
return redirect()->route('newpageid', ['id' => $pageid]);
With basic (unnamed) routes, the correct syntax was return redirect('/newpage/'.$pageid);
You have already found out you can alternatively use named routes.
Last but not least, thanks for having considered the "double submit" issue! You have actually implemented the PRG pattern :)
im using Laravel-Backpack. could we parse some param from view to backpack controller? imagine i have some list of a package. each package has 5 round so every package has 5 button in its row. when i click first button(round 1) it will open the list of item that has round_id = 1.
what can i think is each round button in package list will parse id to route that will call backpackCrud Controller. and that id will used for advance queries for the item list
my button
<i>2</i>
my route
CRUD::resource('package/round/{RoundId}', 'Admin\CrudController');
my crud controller
$round= \Route::current()->parameter('RoundId');
$this->crud->addClause('where', 'round', '=', $round);
but it return an error
Route pattern "/admin/package/round/{RoundId}/{{RoundId}}" cannot reference variable name "RoundId" more than once.
what i know is we cannot parse param to restfull controller cause restfull is for quick crud. so what should i do for parse id from view to controller. or maybe there is beautifull way to make the queries? i trully appreciate that
Many thanks!
i found the way to avoid that.
it CANNOT be like:
CRUD::resource('package/round/{RoundId}', 'Admin\CrudController');
we have to follow the pattern of the default route like
CRUD::resource('someRoute/{someId}/someSecondRoute{someSecondId}', 'Admin\CrudController');
with that way, we can get the first and second paramater in controller with this:
$firstParam= \Route::current()->parameter('someID');
$SecondParam= \Route::current()->parameter('someSecondID');
hope this help someone else ;)
I want to show all users page wise initially. So if I browse http://mydomain/user it will redirect to http://mydomain/user/page/1 and so on. But if I browse http://mydomain/user/1 it will show only single user with id of user.
http://mydomain/user/1 >> it works fine. But as I want pagination so I want to redirect http://mydomain/user to http://mydomain/user/page/1 always
My Routing Info is:
$route['user/(:num)'] = 'user/index/$1';
$route['user'] = 'user/page/$1';
But when I pressed to http://mydomain/user it does not rout to user/page/$1. I have index() method which output to single user information if I give slug. so get a page wise list I used routing and page method. But it is not working. it gives 404 Page not found
Could anybody have solution please..
I think you need to look at the manual for routing:
http://ellislab.com/codeigniter/user-guide/general/routing.html
As far as i can see your second route doesn´t make much sense, you are calling the method page() of your User class - and trying to pass in $1 which does not exist. I think you need to explain better what you want to achieve with your second route - I don´t really see why you need it at all at the moment.
I have a form to update some profile information. After making changes when the user clicks on the submit button my to be redirected to the profile page.
so after inserting the updated information into database I have the following code to redirect to the profile page:
database query goes here...
redirect('studentprofile/get/$id');
Here the $id is the the profile id and "get" is the function and "studentprofile" is the controller. But this is not working at all. It seems like the "redirect" is not getting the value of $id.
When the user submits data it shows an error saying "The URI you submitted has disallowed characters." and the URL looks like this
http://localhost/sundial/studentprofile/get/$id
would you please kindly tell me what is wrong with my script? Just for your information I am using Codeigniter
Thanks in advance :)
You need the redirect path string to be in double quotes:
redirect("studentprofile/get/$id");
or write it like this:
redirect('studentprofile/get/'.$id);
You are using single quotes use single quotes instead and btw that is not an issue of CodeIgnitor. Read more about strings: http://www.php.net/manual/de/language.types.string.php#language.types.string.syntax.double
I have my own nice link http://www.link.com/sometext, now I would "enhance" this having the opportunity to write something like http://www.link.com/sometext?parameters=myParam cause I need to send a parameters to the article called by sometext.
Can I do something like that??? How can I pass parameters through the URL???? How can i get it's value?
Regards
You should use the standard Joomla way to retrieve GET/POST requests. This link should get you started:
http://docs.joomla.org/Retrieving_data_from_GET_and_POST_requests
$address = JRequest::getVar('address');
EDIT - just saw your other comment. To use PHP inside article, try something like Sourcerer: http://extensions.joomla.org/extensions/edition/custom-code-in-content/5051