Remove specific parameters from URL while leaving others intact - php

I have a few filters on my view which a user can select. Let's say in this example it is a webshop and the user is viewing a page to buy t-shirts. On the sidebar the user can select a few parameters which will be added to the URL:
https://www.myshop.com/shirts?size=22&gender=male&somethingelse=true
Now when the user clicks on view all sizes, I want the size=22 to be removed from the URL while keeping the other parameters intact:
https://www.myshop.com/shirts?gender=male&somethingelse=true
I found somewhere to do that, I have to do the following in my blade file (Mind you I need to do this from the blade view, not from any controller or helper method):
View all sizes
But this does not work, it keeps the size=22 in the URL. What am I missing here, or is there perhaps a different approach to this?
Edit: Added dump of request()
In my example I am using a webshop but in my actual site I am using date and category, but the base functionality is the same.

In the end, this did work after all:
View all sizes
I think I did something wrong in the beginning. After revisiting this solution, it worked.

Related

How can I automatically redirect a wordpress page to itself, with added information in the URI?

This is the situation:
I made a portfolio page for photographies. The gallery is already on the front page, so the first thing the visitor sees when calling www.homepage.com (example)
This loads all the images into the gallery, despite their category. Each image does have one or more categories assigned (one of which is 'all', which all pictures have, obviously).
The filter works as following: the navigation buttons for choosing a category are actually submit-buttons, that print the according category name into the URI, like so
www.homepage.com/?all=
The PHP reloads the page and puts this '/?all=' into a variable, strips it of all special characters and leaves 'all', which then filters the images as wanted and shows only those.
I hope it makes sense so far.
The problem is, that I want the first thing for the visitor to see be this:
www.homepage.com/?all
so he only does see all the images with that category assigned to it (I mentioned that all images have that, but that's not entirely true, my client wishes to exclude certain categories that are less important, but can be found by choosing this particular category in the menu. Achieved by simply not assigning the category 'all' to them)
So far I tried to change the standard URI of the page to this link via my hosting settings, which didn't work (too many redirects error).
I also tried a wordpress function to redirect the page with the added info
<?php wp_redirect( home_url( '/?all' ) ); exit; ?>
but again, the redirect-error strikes.
And since I didn't use wordpress in quite a while I'm already at my wits' end.
Is there any way to solve this elegantly, without reprogramming the whole filter system?
Thanks in advance :)
-edit-
I might want to add, that this should only be done the first time someone visits this particular page (so it doesn't negate the filtering process upon reloading this very page) and it obviously shouldn't affect any other page ( About, Contact etc.)
I solved this in another way (which was actually dead simple...)
Before I fired the WP function that put all the relevant post-data into the $args array I added an if-statement right in front of it that checked whether the $category Variable was empty or not. If so (and this is the case when the function prior to that cannot pick data from the URL) it will assign the variable "all" to it by default.
The Code then looks like this:
if(!$cat){
$cat = 'all';}
and that's basically it.

HMVC internal/external requests and routes?

I think I understand the concept of HMVC after reading this question and answer https://softwareengineering.stackexchange.com/questions/220480/hmvc-and-database-connections; an extract from an answer is below:
Let's assume you want to have a view that enables a user to make a
comment to a blog post. You would have fields for name, e-mail, title
and comment, but you also want to have a field country displayed as a
dropdown. In the action that displays this view you would make a
database query that loads the countries and then populate that
dropdown. Which is ok, but it forces you to duplicate the query and
the view required to display the countries if you need it in another
part of your application. A better approach would be to create
separate controller for countries with an action that returns a view
with the dropdown and then render that action whenever you need to
show a list of countries.
What I cannot wrap my head around is that if I can internally request a controller/model/view which just displays a widget (e.g. a country select box), doesn't that mean that by accessing that url from a browser will also just show that view?
How is this managed in HMVC, are routes defined as internal/external only, so matching an internal route with an external request would show a 404 page?
Is this generally how it is done and is the HMVC description/definition above satisfiable with the general use case of it in most web applications?
Showing the output of a sub-request in the browser shouldn't be a problem, so I wouldn't bother, especially that those URLs are not known by the user and it's safe to output the widgets separately.
Despite the above, you could, as #deceze mentionned, not attach those controllers to any routes. If you have a "default" route (matching all requests), then you would have to disable it.

Need Joomla 2.5 Custom Component Router.php Explanation

I'm completely lost on how to use the routing capabilities of Joomla for a custom component.
Here is an example link that is being sent to the custom component through a form submission:
http://superiordash.com/products/dash-kits/index.html?make_id=8&model_id=6&year_id=48&option=com_mmg&view=products&page=list&sel_make_id=-1&sel_model_id=-1&sel_year_id=-1&Itemid=580
What I want to do is grab the make_id, model_id, and year_id, find the corresponding values in the database and use them for the url as such: products/dash-kits/YEAR-MAKE-MODEL.html
So for the example link above:
http://superiordash.com/products/dash-kits/2002-acura-rsx.html
Any ideas from the greats out there?
Also, from what I understand from the documentation - Am I going to have to find a way to explode the rest of the query or it will be attached at the end of url? And if so - is there a way to explode every part of the query except year, make, and model, no matter what it is?
Any help would be most grateful. I've been searching for solutions, half solutions etc. and will continue to do so.
It's actually quite easy. You will need to use 2 functions in your router.php:
ComponentNameBuildRoute
and
ComponentNameParseRoute
The build route will return an array containing the elements to be displayed in the URL. For example, for a link that is http://www.test.com/products/category-name/product-name, the build route function will return array('category-name', 'product-name'); . The array is passed to a Joomla function automatically to generate the SEF URL.
The parse route function will translate the SEF URL into a GET URL. The function will receive $segments as a parameter, and that segments will consist of the portions in the URL, such as category-name and product-name. In that function, you will need to get the ID of the category and the product, and return an array that is something like array('category_id'=>$category_id, 'product_id'=>$product_id);
You can check the router.php for the banners component (which is the simplest component) and use it as a startup point.

Dynamically Add Multiple Cgridview on a single Page

I'm trying to figure out how to let the user add any numbers of tables or CGridview on a single page. So right now the page has two gridviews in it which will stay fixed. Now i want to add an add button somwhere, clicking on which will give the user another gridview, and so on.
How should i proceed with this. I mean is there an easy way to do this, without resorting to writing everything from scratch.
What i was thinking was to create a new view file using file_put_contents() or fwrite() dynamically everytime the user wants another table on the page? Now following in my line of thinking from where would i create these dynamically view files.
Should i write the whole code of the view and put it in a string, in the controller, and call file_put_contents() from there.
This would cause another problem as the filter needs a specific ajaxUpdate url like this
'ajaxUrl' => Yii::app()->createUrl('project/AjaxUpdate'),
.
Which would entail i would have also have to dynamically create the actionCode in the project controller for the filter in that dynamic grid to work. eg. project/AjaxUpdateDynamic1, project/AjaxUpdateDynamic2, etc.
So i'm kinda stuck with this problem. I would really appreciate if someone points me in the right direction.
Thanks, in advance,
Maxx
if you had an action for ajax loading your gridviews, you can then set your ajax url to that url and you'd have filtering possible for your model, you can even put multiple gridviews for multiple data providers that can be loaded via a parameter that you have sent along with click of your button and an input.

open link redirect to page with id working on doctrine

I didn't know how to ask professional so if topic is wrong, please correct it.
My problem is quite complicated. I was training on symfony webpage how to generate form and then send this data to another page.
But now i would like do something different. I would like create page xyzSuccess.php.
Then generate 29 links on this page. Each links would have its own number.
Each link would redirect to the same page. For example numberSuccess.php. After that, this site would give me data of the number which i clicked.
I will show the example :)
Page xyzSuccess.php have links, the third one is http://localhost:8080/web/number?nr=3
I click on it and i go to numberSuccess.php, the page give me number 3
After the page got number, also take from any datafile information under that number 3 ( i don't know, maybe any file wchich can store symfony / array somewhere?.)
I dont know how to do this, i don't want use any database eq. *sql
So far i created only page xyz.php which use php for loop. I see that action.class.php would work with it if i would use submit button, but i really dont have any idea how make this working with links. And... that problem with storing data :( maybe create file in lib/form ?
corrected the link to page (deleted success which used only in templates), guy under is right :)
First of all, you're talking about URL's like /web/numberSuccess... That probably means you've misconfigured the root. Also see this question, asked today.
Then it's common to give your actions names like number, and then in you're actions file you have the executeNumber action, which then renders the numberSuccess template. So you shouldn't include the Success in the action name/URL.
Then, your question:
What I would do, if you don't want to use a database:
Create a file links.txt in your /data directory, and on every line create an url, followed by a space and then the title of your link.
In your list action open the this file using file_get_contents(), explode it on the newline-character, and assign this array to the view.
In your view loop through the array, use the array index as your number, and explode each item on the first space, so you can display the title.
In the view action your open and explode the links file again, and now you can pointer directly to the index, explode again and you have the URL.

Categories