how to use a controller variable in a php code block

Permalink
I'm sorry to ask this beginner's question. I just can't figure it out myself with only the documentation.

I have a single page with its view at /application/single_pages/zzztest/view.php
I have set up a controller at /application/controllers/single_page/zzztest.php

In the controller I have set a variable
$zzz
to be used in the view.php directly as well as through a Php-code-block that I've put in this single page.

the variable shows up in the view.php, but i can't use it from within the Php-code block.

How should I treat this variable in the controller so that the code in the Php-code block reads this variable?

in /application/single_pages/zzztest/view.php:
<!-- other code -->
<div>
test is: <?php echo $zzz; ?>
</div>
<!-- other code-->

this works: I can see the contents of the zzz-variable, which has been set in the controller:

controller: /application/controllers/single_page/zzztest.php:
<?php
namespace Application\Controller\SinglePage;
use Concrete\Core\Page\Controller\PageController;
class Zzztest extends PageController
{
public function view()
{
    $this->set('zzz', 'TESTzzz');
}
}


the php in the Php code block that I've added on this single page:
<div>
test is: <?php echo $zzz; ?>
</div>

This last variable is not visible.

What do I have to do in order to make the variable from the single page controller active in the Php code block on this single page?

C5 v8.5.5.

terano
 
JohntheFish replied on at Permalink Reply
JohntheFish
Put a die('me') in your controller to check it is even being run.

Often the problem is the finicky path and class names don't relate in the way the core expects and the view runs without a controller.
terano replied on at Permalink Reply 2 Attachments
terano
Hi, the page 'dies' as expected. see screenshot.

I now added a php-isset check to both the view.php and the code in the php-code block, with the same result: the variable is not recognised in the php code block:

view.php:
<div>
<?php
if(isset($zzz)) { 
    echo "variable zzz is set in view.php and its value is: $zzz"; 
} else { 
    echo "Value of variable zzz is not set"; 
}  
?>
</div>


and the code in the php-code block on that same single page:
<div>
<p>
<?php 
echo "value of zzz through echo within a php-code block:<br />";
if(isset($zzz)) { 
    echo "zzz is set and its value is $zzz"; 
} else { 
    echo "Value of zzz is not set"; 
} 
?>
</p>
</div>


Could it be possible that the php code block or my theme unsets the variable? Should I do something else when I want that a controller -variable is available also for the blocks (in Areas) on that page? Should I declare them globally or something like that?
Thanks!