It seems to have finally happened. You can now add PHP in a Block as of 612, but with one caveat. You have to make an entry in the PageCompose table and you have to add your PHP via phpMyAdmin. This shouln't be too hard as it's a lot easier now than before.
Here's a simple example:
The above example uses an echo function. For example:
echo "Look at me I'm the PHP!';
Here's one that uses a Flash chart and PHP. There's a few additional code that I had to write, but it's the same concept.
So what has changed? Well take a look at this:
function getBlockCode_PHP( $iBlockID, $sContent ) {
ob_start();
eval($sContent);
return ob_get_clean();
}
The
function can be found in the BxDolPageView.php file located in
inc/classes. That new function was introduced in 612 and as such it
will parse PHP code. Comapre that to the typical ECHO function:
function getBlockCode_Echo( $iBlockID, $sContent ) {
return $sContent;
}
Notice the ECHO function does not have the ob_start(), eval() or the ob_get_clean() function.
HOW TO ADD A PHP BLOCK
-----------------------------------------------------------------------
To add a PHP block, you have to do the following:
1. Make an entry in the PageCompose table.
2. Add your PHP Code in the "Content" field of your new block entry.
3. In the Admin, you have to make sure it's active in the page.
STEP 1 : MAKE AN ENTRY IN THE PAGECOMPOSE TABLE
-----------------------------------------------------------------------
Login to your phpMyAdmin and run this SQL INSERT statement:
INSERT
INTO `PageCompose` (`ID`, `Page`, `PageWidth`, `Desc`, `Caption`,
`Column`, `Order`, `Func`, `Content`, `DesignBox`, `ColWidth`,
`Visible`, `MinWidth`) VALUES ('', 'index', '960px', 'PHP BLOCK', 'PHP
BLOCK', 2, 2, 'PHP', 'echo "You can now have PHP in a block!";', 1, 50,
'non,memb', 0)
It will make an entry in your table with the
necessary field values. The most important value is the value that we
add for the field Func. It has to be "PHP". Take note that a block
function is identified in the database by what it appended. For
example, the name of the function we are working with is
"getBlockCode_PHP". Notice the "_PHP" in the function name. That tells
Dolphin to look for the record in the PageCompose table that has "PHP"
as the value in the Func field. If we created a custom function called
getBlockCode_TEST, then we would need a corresponding Func value in the
PageCompose table of "TEST". This is how the function matches up with
the value that is found the database. In our example, it will spit out
the value found in the Content field. That's where the PHP code would
go.
STEP 2 : ADD YOUR PHP CODE
-----------------------------------------------------------------------
Once
you've made the record entry in the PageCompose table, the rest is
pretty easy. Just add you PHP code in the Content field and save. Go to
step 3 to get a sample of a db connection and display your memebers.
STEP 3 : ADD THE PHP BLOCK VIA THE ADMIN
-----------------------------------------------------------------------
The
SQL INSERT statement provided will automatically add the PHP Block in
your admin under Builders so the only thing you would need to do is
move the block to where you want it to be.
****One of the quirky
things about the Dolphin is how it keeps and show information. In some
cases you may need to refresh the page or move a block to make sure
that your changes will update. For example, moving a block to another
location in the page builder will usually do it.
Below is sample PHP code that will list all your members. You can copy and paste this bit of code in the PageCompose table.
$jt_dbHost="localhost";
$jt_dbLogin="yourlogin";
$jt_dbPass="yourpass";
$jt_db="yourdb";
$connection=mysql_connect("$jt_dbHost","$jt_dbLogin","$jt_dbPass") or die("Couldn't connect to the server.");
$db=mysql_select_db("$jt_db", $connection) or die("Couldn't select a database.");
$sql="SELECT * FROM Profiles";
$sql_result=mysql_query($sql,$connection) or die("Couldn't execute query!");
echo "PROFILES LISTING:<BR>";
while($row=mysql_fetch_array($sql_result)) {
$NickName=$row["NickName"];
echo "<br>$NickName";
}
echo "<br><br><br>CONGRATS! The db connected properly.";
mysql_close($connection);
Please try it out and let me know how it goes.
...sip...
If you edit some code in it later, remember to move the block in admin to show your last changes on your website
I have a few more advanced tutorials I am writing, if you're interested in reviewing them please let me know. Send me a PM etc and I will send you the links.
T_T my life is going to be easier I think Im gonna cry months and months on a learning curve with no end, thank you jtadeo...and the boonex dudes who realize that was necessary!
It worked perfectly, now Im wandering if I can include a file and then alot lots of things now can happen!!!
THANK YOU!
James, thanks for this contribution!
I'm trying to unravel the dolphin template puzzle. If I could get a small assist with a few questions, I think I can be on my way.
For example, I'm trying to customize the Groups/Entry page (the page that displays when you click on a group that you belong to from 'my profile' page). see more
James, thanks for this contribution!
I'm trying to unravel the dolphin template puzzle. If I could get a small assist with a few questions, I think I can be on my way.
For example, I'm trying to customize the Groups/Entry page (the page that displays when you click on a group that you belong to from 'my profile' page). see more
I will be updating this at my boonexnerd.com site. I am getting some help updating tutorial files etc.
the second post has a correction - 'the group display page is not one of the pages that Pages Builder tool includes ....'
Bob
I tried following your tutorial above, yet after doing the SQL INSERT statement and viewing it in the DB fine, nothing new appears in my Admin->Builer->Page Builder->Profile
Here is what i added to my db:
mysql> select * from PageCompose where ID=90 \G
*************************** 1. row ***************************
ID: 90
Page: profile
PageWidth: 317px
Desc: Profile Videos
Caption: Profile Videos
Column: 1
Order: 2
Func: PHP
Content: see more
Parse error: syntax error, unexpected '<' in /home/xxxxxx/public_html/dolphin/inc/classes/BxDolPageView.php(281) : eval()'d code on line 1
There is no < on line 281 in BxDolPageView.php .....
Where would I find the evaluated code to review line 1?
OR ..... what's wrong?
.
Any ideas?
Parse error: syntax error, unexpected '<' in /home/ethiomys/public_html/inc/classes/BxDolPageView.php(308) : eval()'d code on line 1
Anyone has a solution?
Is there anyone with suggestion on how to get the PHP block working with php code that contains html or java codes?
Here is mine the couldn't work:
<?php
include "config.php";
include "functions.php";
?>
<script language="javascript" see more
after reading your instructuion
i can't find PHP BLOCK in my BUILDER
what's wrong?
thanks!
Note: I strongly recommend you backup your BxDolPageViewAdmin.php just in case...
--------------------
STEP 1
--------------------
Run the following Insert query in the pageCompose table:
INSERT INTO `PageCompose` ( `ID` , `Page` , `PageWidth` , `Desc` , `Caption` , `Column` , `Order` , `Func` , `Content` , `DesignBox` , see more
can I insert a language string in to this php block?
example:
A user from UK see in this block a link with name "ocean" and the other user from Germany see "oZean".
than you
Let me start by saying that this is just a great tutorial, and @newdreamers' addition is just the icing on the cake. Just one question, is there an advantage to using a PHP block over an HTML block that does an AJAX call out to another PHP script that returns your data?
Seems like either method would get you the desired effect and the AJAX method would let the page load while the AJAX-requested data is loading. On the other hand, there may be great advantages to using the PHP block see more
You can use Ajax with the php block no probs!
I prefer pure PHP for my blocks as it gives me more control of data should I need it in the future.
Best,
James
I have a bad habit of rushing to implement things that are existing in my build.. is this cool for 6.1.4?
And does anyone have any examples of how you used a php block on your site?
It does work with 6.1.4. I have dozens of sites that make use of this technique. Check out my Dolphin site (see my profile) and you will see a Daily Quotes block that randomly generates a quote with each page refresh.
You can also check out okweb's tutorial on showing a Daily Quote and newdreamers tutorial. Both members have kindly gave their time to provide some very useful info on its usage.
Good luck!
I want to add some php script in the Dolphin but still do not know how i may do that. Please guide me
Thanks
You will need to hire a programmer to make it work in the older versions.
I assume, you have started your php code inside of the new PHP Block with <?php and ended it up with ?>, am I right?
So this time skip the opening and closing brackets and leave just the php script you've written and you should be fine.
In other words instead of
<?php .....your php script..... ?>
use this:
.....your php script.....
Hope, it helped
i've tried it and it waorks fine for me until i introduce the mysql_fetch.
the code is:$MySQL = new CMySQL;
$res = db_arr( "SELECT NickName FROM `Profiles`" );
echo "PROFILES LISTING:<BR>";
$row=mysql_fetch_array($res);
echo $row["NickName"];
echo "<br><br><br>CONGRATS! The db connected properly.";
and the output is:
PROFILES LISTING:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result see more
I used db_arr instead of db_res ...
Here's the link:
http://www.boonex.com/unity/blog/entry/How_to_enable_PHP_block_in_the_Page_Builder
Hopefully it didn't get cut off, but if it did here's a tinyurl version of it:
http://tinyurl.com/newdreamer
...sip...
oh well.
If I want another box I guess I just insert another row?
Thanx
CMP
At http://www.mytherapysession.net/m/complete/generalhealth you will see one of the pages that is displayed from my modules/mts/complete/classes/MtsCompleteModule.php
On this page there are a few functions like this:
function actionGeneralHealth () {
if (!$GLOBALS['logged']['member'] && see more