php code

11 posts by 3 authors in: Forums > CMS Builder
Last Post: October 21, 2012   (RSS)

By KCMedia - October 20, 2012

Hi

i have this site we are building and we have a piece of php code that we want to be able to turn on or off when required.

I have setup a single section with a hidden check box and a text box for the php code and then i have put this into the code

// load record from 'mobile_site_admin'
list($mobile_site_adminRecords, $mobile_site_adminMetaData) = getRecords(array(
'tableName' => 'mobile_site_admin',
'where' => '', // load first record
'loadUploads' => false,
'allowSearch' => false,
'limit' => '1',
));
$mobile_site_adminRecord = @$mobile_site_adminRecords[0]; // get first record


and int he body of the code this

<?php echo htmlencode($mobile_site_adminRecord['code']) ?>

but it wont load the code it keeps showing the php code on the page, why wont this work.
Thanks



Craig

KC Media Solutions

www.kcmedia.biz

Re: [kcmedia] php code

By gkornbluth - October 21, 2012 - edited: October 21, 2012

Hi Craig,

I'm not sure why you need to toggle a load records call if you're not using fields from those records in the page, and why there would not be errors thrown if you are calling any undefined indexes when the load records code is not there.

But, why not put the code into the page where you want it and surround it with an if statement, then put a check box in your single record section instead of a text box?

Assuming the check box is called 'show_code', you could use:<?PHP if ($your_table_Record['show_code'] == '1'): ?>
<?php // load record from 'mobile_site_admin'
list($mobile_site_adminRecords, $mobile_site_adminMetaData) = getRecords(array(
'tableName' => 'mobile_site_admin',
'where' => '', // load first record
'loadUploads' => false,
'allowSearch' => false,
'limit' => '1',
));
$mobile_site_adminRecord = @$mobile_site_adminRecords[0]; // get first record
?>
<?PHP endif ?>


That might work.

Best,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] php code

By KCMedia - October 21, 2012

Hi Jerry

nup that didnt work. What we are trying to do is this.

We have a piece of php code for mobile device detection that we want to either have on or off based on what we are doing with the software at any one time.

So the client can do into the cmsb and click hidden check box and this will stop anyone with mobile phone from being redirected to the mobile version of the site and they are displayed the normal website.
Thanks



Craig

KC Media Solutions

www.kcmedia.biz

Re: [kcmedia] php code

Craig,

I'm not sure from your description what actually didn't work. The code was not hidden? The lack of code didn't work the way you wanted it to?

Not extremely elegant, but you could set a variable in the code block IE:<?php $showing = "Yes" ?> and then echo the $showing variable IE: Showing?: <?php echo $showing ?> in the body of your page as a test to see that the if statement is working.

If the if statement is working as it should, could you be a bit more specific about exactly what is not working and post your page so the code can be seen in context?

Thanks,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [kcmedia] php code

By Toledoh - October 21, 2012

How about;

<?php if ($record['tick_box_field']): ?> ...your code...
<?php endif ?>


Then, if the tick box is ticked - it'll show your code, if not ticked, it won't show your code.
Cheers,

Tim (toledoh.com.au)

Re: [Toledoh] php code

By KCMedia - October 21, 2012

ok i think everything is getting out of context.

Here is the code we need to either be on or off in the page when the client wants to turn it on or off.

<?php
@include("Mobile_Detect.php");
$detect = new Mobile_Detect();
if ($detect->isMobile() && isset($_COOKIE['mobile']))
{
$detect = "false";
}
elseif ($detect->isMobile())
{
header("Location:http://mobile.botanybaygamefishing.com.au");
}
?>

i have this code in a text box with a hidden check box in the single section of cmsb.
Thanks



Craig

KC Media Solutions

www.kcmedia.biz

Re: [kcmedia] php code

By Toledoh - October 21, 2012

I would remove the php from CMSB and just leave the text box.

Then have;

<?php if ($mobile_site_adminRecord['tick_box_field']): ?>
<?php
@include("Mobile_Detect.php");
$detect = new Mobile_Detect();
if ($detect->isMobile() && isset($_COOKIE['mobile']))
{
$detect = "false";
}
elseif ($detect->isMobile())
{
header("Location:http://mobile.botanybaygamefishing.com.au");
}
?>
<?php endif ?>


or, if you really have to have the php editable within CMSB;

<?php if ($mobile_site_adminRecord['tick_box_field']): ?>
<?php echo htmlencode($mobile_site_adminRecord['code']) ?>
<?php endif ?>


However, there are issues in having the php within CMSB...
Cheers,

Tim (toledoh.com.au)

Re: [Toledoh] php code

By KCMedia - October 21, 2012

Hi Tim

nup it still wont show up, i have done what you said with the php code in the main code and just the tick box to turn it on or off and still nothing.
Thanks



Craig

KC Media Solutions

www.kcmedia.biz

Re: [kcmedia] php code

By Toledoh - October 21, 2012

Try just having;

<?php echo htmlencode($mobile_site_adminRecord['tick_box_field']) ?>
and make sure that it is producing a '1' when the tick box is selected, and nothing when the tickbox is unselected.

Then, if it's working, try;

<?php if ($mobile_site_adminRecord['tick_box_field']): ?>
test
<?php endif ?>


and check that "test" is appearing when selected.
Cheers,

Tim (toledoh.com.au)