I am having a small issue with my Laravel 5.2 application. The problem is with a page made to adjust database entries.
When data has been adjusted and a button is pressed to update the database, it works great. Problem is, I would like to redirect back() to the previous page, but this page has been set up through data from other pages.
So when I redirect back, it error's and says that certain parameters are not defined. Is there a option, that I can implement a very static redirect to the previous page and all the data that has been loaded in the page?
Like the go back function that web browsers have?
Solution
I added the following code in the Controller function where the page is made to adjust the database entry:
Session::flash('url',Request::server('HTTP_REFERER'));
And as a redirect I have this:
return Redirect::to(Session::get('url'));
Related
I am working in laravel 5.1. I have three pages in routes Home,show,short.
I also have blade file for home and short routes
I have a form on home page .After submit the button on home page I want that
(1). the data will be save at the database via post request which code has been written in a method postdata() which routes is show..
(2). I want to display the results based on the inserted data after doing query from database which code has written in showdata() method of short route .
I want all that happen after clicking the submit button without refreshing the page.but my problem is that i have two routes and in url of ajax method how can i give two url. please suggest me the better and efficient way to do that.
I have an application where I use ajax to update the comments & Like count.
I am using Codeigniter page caching http://www.codeigniter.com/user_guide/general/caching.html
and set following code to recreate caching every 60 minutes
$this->output->cache(60);
Problem is when somebody enter a new comment, DB operation is happening (Because of Ajax call), But the Newly inserted comment disappears after the page refresh, because of the cached HTML page. How to handle caching and also dynamic content to change?
The main purpose of caching is to save server resources on page load (i.e. so the server doesn't need to fetch all the dynamic data every time its loaded).
It sounds like you are using the AJAX function to both submit the data but also modify the webpage on the client side simultaneously. When the user then refreshes the page, this will fetch the content back from the server, in this case the original cached content that was generated before the comment was made and is therefore operating exactly as it should.
If you have a true requirement for caching this page, you could consider deleting the cache, which would force it to be rebuilt on the next page load whenever a comment is made. Placing the following line of code in your controller (in the function that received the AJAX data) should do it:
$this->output->delete_cache('foo/bar');
I found the solution.
To delete a cache file you need to use the following function
$this->output->delete_cache('CONTROLLER/FUNCTION');
Note: No Slash before or after.
In my Case i was using custom routes in codeigniter. When user type example.com it is routed to example.com/CONTROLLER/FUNCTIONNAME and that too default landing page.
So i created a new function. Please refer here
I have a login form spread across my website on different pages for different situations that are all used in the same POST controller. In the POST controller I always redirect->back() so it goes to the previous page the visitor was on. However, now I need it setup differently. I need it to know which page they came from and based on that previous page know which page to redirect the user to.
So basically I need a Route::getCurrentRoute()->getPath() for the previous page. So it can be something like this:
Route::getCurrentRoute()->getPath() == "some/url" then go to some/url/2
If I actually use getCurrentRoute() it just shows my POST route and not the route the visitor is coming from.
So I am creating an application that manages users with the CRUD operations using Route::resource.
I have the following pages:
index page (get) - which shows the list of users. Within each user row there are two buttons that links to the edit() method and show() method.
edit page (get) - which shows the form with pre loaded saved data so that the can edit from there.
show page (get) - which displays the users's information
update (put) - which saves all the fields provided by the user to the database.
After when the I update, I want to redirect to the index page (which shows the list of users)
if($user->save()){
Session::flash('usersaved', 'The user: '.Input::get('user_name'). ' was saved');
return Redirect::route('admin.users.index');
}
The redirect back to the index works correctly with the message BUT, right after I press the link that goes the to show() method (only on the edited client) and then press the back button on the browser (Google Chrome), it takes me to the edit() method not the index() method (list of users)!
Whats going on here?
Many thanks!
If you have no problem with other browsers, I guess this is caused by Chrome not adding a history entry after the redirect (Chrome developers do not consider it to be a bug while the rest of the world seems to).
Lets say I have a Page with a List (list.php).
I click on a row on that list to Edit that record. I go to a edit.php Page.
I have 3 buttons on that edit.php page. Save, Apply, Cancel
Save button - Saves the Record and returns to the (list.php) Page
Apply button - Saves Record but stays on the same page (edit.php)
Cancel button - No save, just return to the (list.php) Page
But now image if I can access for edit that item on a different page. How do I return to that calling page?
Do I add a parameter(code) to the URL? something like a Page Origination Code?
Do I save the previous page URL in a session? (bad, they can right click open another page and that would be saved to session url)
Am just curious to how others return to a previous page after a SAVE.
you can the server variable $_SERVER['HTTP_referrer'].
They are other ways also you can store in session the current page and use is processing page.
Adding a parameter to the URL is the only reliable though quote ugly way.
That's why such an in-place editions nowadays often being implemented using AJAX, and this very site is a perfect example.
However, there are different cases.
Login page is imperfect example for example, as you always have a form instead of just a link, and thus you can always store the current page in a hidden form field.
Another approach is possible if you are using some sort of front controller, and all requests actually being directed to the single index.php file which runs appropriate script based on the URI.
in this latter case you will need no more than mere a redirect to the current page.