Special Php includes

Permalink
Hello again,

First of all thank you for this really amazing product! It's really cool!

Now, I have this problem:

I need to include a piece of php code into every page on a site. It is not a pure php piece of code but one that contains Concrete5 methods calls like Page::getByID(), Page::getCurrentPage() and such.
I would like that piece of code to be hidden from Concret5 (i.e. not to be available in concrete5; only through ftp directly in the site's folders).

So, I created on my computer menu.php that contains the custom php code and I added in theme's default.php:
<?php include('menu.php'); ?>

I also tried with
<?php $this->inc('menu.php'); ?>

same result.

After uploading the theme (only default.php but no menu.php 'cause I don't need menu.php to be in concrete5) and after putting the menu.php in the expected directory the main page of the site croaks:

Fatal error: Call to a member function getCollectionParentID() on a non-object in /home/[...]/themes/Baza/menu.php on line 3


So I suspect it is doing the include but cannot launch the concrete5 method (probably because it is called before creating the page object?).

If I add the code through concrete5, as a block, using the nice "PHP block by ND" addon, it works ok but it is editable and visible.
If I add it to the scrapbook, I could hide it form others (in my personal scrapbook) but it needs to be added manually to every page of the site which is not convenient.

So, how can I do it? Beware that it is not a simple php include as this works very well (with the help of PHP block by ND)! It is about including php with concrete5 methods inside and the included file to be out of concrete5's scope.

Thanks in advance,

Lian

 
jordanlev replied on at Permalink Reply
jordanlev
Where did you put the menu.php file on your server (in what directory)?
What is the code in the menu.php file?

You should be able to do <?php $this->inc('menu.php'); ?> in your theme template files and everything should work fine (this is how almost every theme already works -- they include separate files, usually "elements/header.php" and "elements/footer.php" -- that is, two files called "header.php" and "footer.php" inside the "elements" directory in the theme directory).
csebe replied on at Permalink Reply
Hello jordanlev,

I don't know what happened... it works now!
For sure I left it non-functional last night (I'm gmt+2) and now I tried to verify my setup in order to post a reply to your post and it is working...

Chronologically, first I placed menu.php in the website root but it was giving this error:
Warning: include(menu.php) [function.include]: failed to open stream: No such file or directory in /home/recolamp/coltverde.ro/packages/nd_php_package/blocks/nd_php/view.php(4) : eval()'d code on line 1
Warning: include(menu.php) [function.include]: failed to open stream: No such file or directory in /home/recolamp/coltverde.ro/packages/nd_php_package/blocks/nd_php/view.php(4) : eval()'d code on line 1
Warning: include() [function.include]: Failed opening 'menu.php' for inclusion (include_path='/home/recolamp/coltverde.ro/libraries/3rdparty:/home/recolamp/coltverde.ro/concrete/config/../libraries/3rdparty:.:/usr/lib/php:/usr/local/lib/php') in /home/recolamp/coltverde.ro/packages/nd_php_package/blocks/nd_php/view.php(4) : eval()'d code on line 1


So I copied menu.php into theme's directory and this generated the message from the first post, which means that at least concrete5 could have find menu.php. I left it like this last night.

But now, as the include works ok, I tried to modify menu.php to see if if really works, and it is reading the menu.php from the www root (i.e. /home/recolamp/coltverde.ro/ ), which apparently is not even in the include_path if you look in the message above. Or maybe it is the '.' dot?

The only thing that comes to my mind is that is a problem of refreshing cache at concret5 level.
But I'm happy 'cause it started working as expected.

Thanks for your reply,

Lian