Forum
Two URL types behaving differently
I've got two types of URL's on a list and detail page
One is generated from a select/submit form... .../category.php?type=type/office/
And the other from the category tag/s at the bottom of a detail page... .../category/type/office/
Both URL's extract the correct list and detail information but a tiny "icing on the cake" thing is pre-populating the select menus the same as .../category.php?type=type/office/
does. The latter URL fails because catPath
does not match {current_type_category}
. I can't spot why that should be, seeing that everything else works
PHP...
// Get cat into current_category
PerchSystem::set_var('current_type_category', perch_get('type'));
// This create the catergory tags set
perch_categories(array(
'template' => 'category-type-select.html',
'set' => 'type',
));
Template
<perch:before>
<p class="smallprompt">Property search:</p>
<form method="get" action="category.php">
<select id="cattype" class="typeselect" name="type">
<option value=""/>Any type</option>
</perch:before>
<option value="<perch:category id="catPath" />" <perch:if id="catPath" match="eq" value="{current_type_category}">selected</perch:if>><perch:category id="catTitle" /></option>
<perch:after>
</select>
</perch:after>
What does
perch_get('type')
return and what does your route look like?I'm using Perch 3. No routing?
Using
../category.php?type=type/retail/
andperch_get('type')
returns{current_type_category}
in all three categories correctly astype/office/
,type/retail
etc. Which then matchescatPath
However, using the URL as
.../category/type/retail/
or.../category/type/office/
this first two selection options andcurrent_type_category
returns correctly, However on thesecatPath
returnstype/industrial
which is the last in the category set regardless. So it's only using the last selection where it works.Before you get anywhere near a template, what's the value of
perch_get('type')
?From the detail template, the value of type is
<perch:category id="catPath" />
Sent from the detail template category link tags
Hi David,
When the URL is
.../category.php?type=type/office/
,perch_get('type')
gets you the catPathtype/office
.When the URL is
.../category/type/office/
, what do you get if you output theperch_get('type')
? Do you gettype/office
? Or justoffice
?Your
perch:if
tag is testing against a full catPath. So you need a catPath liketype/office
.office
by itself is a catSlug.Hi Hussein,
Both URL's
.../category/type/office/
and.../category.php?type=type/office/
gets the correct valuetype/office
using...Hence why I'm puzzled.
Here's the full php of the select form...
Plus checking the value of type and area are correct before and after.
Umm I think catPath includes a trailing slash. So a catPath would be
type/office/
nottype/office
.I'm sure
.../category.php?type=type/office/
gets youtype/office/
, but perhaps you're not be getting the trailing slash when using.../category/type/office/
?Well spotted. Didn't see that.
.../category/type/office/
is returningtype/office
without a slashIs there a way to fix this?
You could add the trailing slash if it doesn't exist:
Thanks, I was thinking of using `substr'. Just thinking if there's a Perch way.