Single pages and pass-through of includes...

Permalink
Hello - I've created a view.php in my themes directory which has several includes; header, footer, etc., but also a 'globals.php' file that has a bunch of functions for interacting with a database.
The problem I'm having is that when I create single pages and add them via the dashboard, they aren't working because the functions in that 'globals.php' file aren't loaded. I'm sure I'm missing something simple here, but I'm at a wall.
If I remove the function calls from the single pages, they work fine, inheriting all the other content/properties of theme/view.php.
What am I missing?
TIA

hypnotoad
 
LukeBMM replied on at Permalink Reply
Are you using the default view.php in your theme? Did you add a line like this?
$this->inc('elements/globals.php'); ?>

It sounds like you updated your page types to use the include, but not view.php - which acts kind of like a page type for all single pages.

Edit: Wow. I failed at reading comprehension. Sounds like this is exactly what you've already done.
hypnotoad replied on at Permalink Reply
hypnotoad
Hey Luke,
Yep, that exactly what I have in my view.php file:
$this->inc('elements/globals.php');


I also tried a more direct include:
require_once('elements/globals.php');


But the functions contained in that script are not being passed through to the child pages of view.php (in the single_pages folder)...
BTW, the regular pages in the site (that use default.php, for example) are working just fine.
I'm not even sure what next steps I should take in troubleshooting this. :-(
JimboJetset replied on at Permalink Reply
JimboJetset
Hi..

I'm working this off the top of my head here but couldn't you use something like...

<?php require_once($this->getThemePath().'/elements/global.php'); ?>
hypnotoad replied on at Permalink Reply
hypnotoad
Thanks Jim, but when I tried putting that line in my single page I got a "failed to open stream: no such file" error.
The path listed in the error is the correct one, so I'm really puzzled...
JimboJetset replied on at Permalink Reply
JimboJetset
OK... it try this...

<?php require_once(DIR_BASE.'/themes/yourtheme/elements/global.php'); ?>
hypnotoad replied on at Permalink Reply
hypnotoad
OK, I got it working but only if I include the full path WITHIN the single page, i.e.
require_once(DIR_BASE.$this->getThemePath().'/elements/globals.php');

Seems silly to have to put that line in every single single page, when it should just have to be in the view.php file, but unless someone figures out a better way, I guess I'll have to do it this way. Thanks for your help!
hypnotoad replied on at Permalink Reply
hypnotoad
I forgot to mention one strange thing... If I did the include with the path as "/themes/myTheme/elements/globals.php" it didn't work; but, if I changed the path to not have the leading forward slash, it did work. What might be going on there? I'm developing the site using MAMP on my local machine (so that it's a virtual apache server)...
esand replied on at Permalink Reply
It sounds very strange that the other includes in your view.php file would get included, but the globals.php file would not. Have you checked your webserver error logs to ensure you're not overloading functions or something?

Also, the difference between your two paths there is that a leading slash means start from the root of your filesystem (in *nix that's the root of the entire system, in Windows that would be the root of your C: drive or wherever your site is running from). Without the leading slash is a relative path, and it will look for your file relative to whatever working directory PHP is currently in at the time of hitting that include line.