
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...
About BoonEx•Terms•Privacy•Contacts•© BoonEx (ACN 127966581)
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!