Single pages, parameters, and getting at them from blocks within the single page.

Permalink 1 user found helpful
I am working on a fairly complex single page to show a whole sub-tree of legacy content. This content is controlled by the path below the single page, as split into parameters by C5.
The single page controller view function is
function view($p1,$p2,$p3,$p4){

This is all working nicely as a single page, but I also want to code some new types of block, which when added to areas on the single page, will adapt their behaviour based on the same parameters (P1...P4). The intent is to provide some later flexibility on how the single page presents the legacy content without having to edit code in the single page, and also to allow the same blocks to be used elsewhere on the site (though without the adaptive behaviour they would have on the single page).

I have tried putting a similar 'function view($p1,$p2,$p3,$p4)' in the the block controller, but it is obviously not receiving the parameters.

The hack solution would be to grab the original path and slice it up, as C5 does in the core dispatcher & controller, but...

Is there any clean way to get at these parameters, as already extracted by C5, from a block within a single page?

View Replies:
Mireck78 replied on at Permalink Reply
I need this as well ... what I tried so far:

1) Tried to get the current single-page-controller from inside a block-view or block-controller like this:

$c = PAGE::getCurrentPage();
$c->controller->foo(); //no success
$c->getController()->foo(); //no success

2) Tried to use the Request-Object directly from inside a block-controller like this:

/*inside a block-controller function (concrete5.6)*/
$req = Request::get();
$req->getRequestPath(); //this works, but its not what I'm actually looking for
$req->getRequestTaskParameters(); //returns null - so it's not working in this case
$req->getRequestTask(); //returns null in my case
Mireck78 replied on at Permalink Reply
Solution A)
This gets the current request task and parameters of the single-page-controller from inside a block-view of that single page:

/*inside block view*/
$v = view::getInstance();
$cTask = $v->controller->getTask();
$cParameters = $v->controller->getControllerParameters(); 
JohntheFish replied on at Permalink Reply
I see you are also a photographer. My original reason for this was to map my existing photo library/archive structure into pages, a project that has been on hold for ages and still is while I work on other things.

Your solution certainly looks cleaner than hacking the path on '/', so when I eventually get round to revisiting this I will give it a try.
snobo replied on at Permalink Reply
wow, been looking for this solution for a few hours! Thank you!!

My 2 cents: in addition to getControllerParameters(), you can also use getvar() method to access variables my names. Sof if in a page controller you have

function view($p1=null, $p2=null) {
   $this->set('myvar1', $p1);
   $this->set('myvar2', $p2);

then you can do the following in a block:

echo view::getInstance()->controller->getvar('myvar1');
echo view::getInstance()->controller->getvar('myvar2');