C5 fails to render single page using view.php

Permalink
Hi,

I've bumped into a strange issue which I haven't seen before. I have a single page added, and when I navigate to it directly in my browser C5 doesn't render the page properly. By inspecting the source I can see that my header and footer isn't being included.

This tells me C5 is not using view.php in my template to render the single page, for some reason.

The odd thing is that if I browse my site first (e.g. load up the front page, and then go to the single page) - Then the single page renders fine.

This leads me to suspect there might be something wrong with my sessions.

Has anybody else seen this? And can anyone with an insight into the core tell me if my hunch is right? That is: Does your session affect how the core controller/index.php renders single pages?

Thanks! :)

 
Hammertime replied on at Permalink Reply
Trying to bump this - as I have, as of yet, been unable to find a solution - I'm gonna spend a few hours on this problem today, it's just extremely hard to debug :(

Thanks for looking!
Hammertime replied on at Permalink Reply
Alriiight - I figured this one out, but I'm a bit stuck on how to solve this.

Ok, so the problem stemmed from the fact that I was using a localization module that I built which is included in my header. As I quickly found out (more on that later) that I couldn't pass variables to an include - like so:

<?php 
$myvar = "test";
echo $myvar; //"test"
 $this->inc('elements/somefile.php'); 
echo $myvar; //"test"
?>
And then in somefile.php:
<?php 
 echo $myvar; //""
?>


Output from this script would be:

test
test

And not

test
test
test

As expected. So, what I did was use the session variable to save the data I needed to pass to my include script. I used some session code I found elsewhere on the forums here:

<?php
   session_id($_COOKIE['CONCRETE5']);
        session_start();
?>


I ran this before saving my session values - and again in my include before reading my session values. This worked for the most part, except for certain cases where the pages were loaded directly as described in my original post. This caused the $_COOKIE['CONCRETE5'] to be empty, and hence I didn't get my values in my include and this caused the entire page to crash (with the weird result of only the single page html being returned, and not the header and footer html - which sent me on my initial wild goose chase)


Soooo.... The concluding question is: How in gods name do I pass a variable to my include?? Sessions are weird/broken/frustrating in Concrete5, and global variables don't seem to survive an include ....


Thanks for your feedback!
Hammertime replied on at Permalink Reply
PS:

I've tried using constants, using the global $myvar; declaration and a host of other things. It seems like any and all variables and functions (except for Concrete5's own stuff) are completely inaccessible from an include script.

I'm hoping I'm wrong and there's a simple way out ...
Hammertime replied on at Permalink Reply
Ok I have found something approximating a solution. It is ugly and dirty and I don't like it much - but here goes:

global $myvar;
 $myvar = "test";
 $this->inc('elements/testinclude.php');
And then in testinclude.php:
 global $myvar;
 echo "MYVAR IS:".$myvar;


Finally shows that the include script has access to the variable. WTF? This indicates to me that my single page is being treated as if it is inside a function - so I have to break out of it to the global scope - and then do the same in my sub-includes.

I understand the logic behind isolating the scope of the single page, as seen from the object-oriented point of view - but what I don't like is that includes FROM my single page are also segregated and "insulated" from the rest of my code. Maybe this is just how things work, and I'm being ignorant. But I've certainly never seen anything like this before in my many years of PHP coding.
Hammertime replied on at Permalink Reply
One final note:

if you want a variable that you set in your header include to propagate down to a sub-include - you have to define it as global at EVERY level.

Say you have a single page called test.php you need to:

*) Define it as global in your header include
*) Define it as global in your view.php
*) Define it as global in your test.php
*) And finally in your sub include to test.php

Holy guacamole, is all I have to say.