Concrete5: Can $ _GET variable be used for query string in normal page?
How does $ _GET Variable work with Concrete5? Can I use this on a regular page?
I know I can do this with a single page via the url segment, I'm just wondering if this is possible with a normal page.
Example: http://www.domain_name.com/about-us/?name=test ...
source to share
Get parameters available through controllers. In order to use a page or block:
$this->controller->get("parameterName");
An easier way for custom parameters would be to define them in the function view()
page controller. If your page is at http://www.domain_name.com/about-us and you define a pagetype view function of this controller like this:
function view($name) {
$this->set("name", $name);
}
... and name the URL http://www.domain_name.com/about-us/test - then "test" will be passed $name
to your pageview.
Note that the controllers for the page types must be in the / page _types / controllers and are named BlablaPageTypeController
... with "PageType" literally there.
source to share
You can use it in your template. For example, you can capture a variable ...
$sort_by = $_GET['sort'];
And then use that variable in your PageList search, similarly:
$pl = new PageList();
$ctHandle = "teaching";
// Available Filters
$pl->filterByCollectionTypeHandle($ctHandle); //Filters by page type handles.
// Sorting Options
if ($sort_by == "name") {
$pl->sortByName();
} else {
$pl->sortBy('teaching_date', 'desc'); // Order by a page attribute
}
// Get the page List Results
$pages = $pl->getPage(); //Get all pages that match filter/sort criteria.
$pages = $pl->get($itemsToGet = 100, $offset = 0);
Then you can iterate over that array to print information ... for example
if ($pages) {
foreach ($pages as $page){
echo '<a href="'.$page->getCollectionPath().'">'.$page->getCollectionName() . '</a><br />';
}
}
Suitable for C5 Cheatsheet for PageList code.
source to share