Skip to Content Skip to Menu

🎃 Happy Halloween! Treat yourself with an awesome discount! Get 20% off now with code SPOOKY-2024!

[SOLVED] CB Code field does not execute PHP code

8 years 1 month ago - 8 years 4 weeks ago #286393 by Afrikao.com
Hello,
my environment Apache 2.4, PHP 7, Joomla 3.6 and all latest CB Add-Ons.
I tried to create a Tab for user where PHP script will be placed.

I've create a tab PHP and create field CODE using CB Code plugin.
As krileon said "It only executes PHP so anything you can do from PHP you can do from a Code field. Please keep in mind it executes your string as an anonymous function so you don't need php tags."
OK, under Parameters of CB Code field I placed a simplest PHP code

print "Hello World!";

But nothing appear on frontend under user "PHP" Tab. CB Code plugin is published.
Please, advise any idea why it happens and how to execute a PHP code.
Last edit: 8 years 4 weeks ago by krileon. Reason: Added [SOLVED] tag to subject

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48454
  • Thanks: 8280
  • Karma: 1443
8 years 1 month ago #286411 by krileon
Replied by krileon on topic CB Code field does not execute PHP code
It adds your PHP as an anonymous function then executes it while being surrounded by ob functions. Your print output isn't going to do anything because it's self contained using the ob functions. It outputs the return value of the anonymous function so if you want anything to output you need to do a return. Example as follows.

Code
Code:
return 'Hello World!';

See the below to understand how anonymous functions and ob functions work.

php.net/manual/en/functions.anonymous.php
php.net/manual/en/function.ob-start.php
php.net/manual/en/function.ob-end-clean.php

CB Code Field does have output templates though so you could always make a template file that handles the code however you want.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

8 years 1 month ago #286477 by Afrikao.com
Replied by Afrikao.com on topic CB Code field does not execute PHP code
OK, thank you for the hints.
Will try to sort it out.

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum