Hi all,
I have a, I think fairly easy, question, but I can't figure out what I'm doing wrong. I have a function which i call with PHP's function eval
. I'm expecting an, selfbuilt, ArrayList to get as a result. But instead when I use gettype
I see the result is NULL
. Even though I'm using return
in the eval-ed function.
As far as I'm aware I'm playing it by the documentation, but somehow it's not working. Any suggestions?
Code fragment
<?php
$widgetList = new ArrayList();
for($i = 0; $i < $selectedTemplate->Regions->count(); $i++)
{
$region = $selectedTemplate->Regions->item($i);
if($region->Widget->selectiveContent == 1)
{
$widgetList->add($region->Widget);
}
}
if($widgetList->count() > 0)
{
?>
<tr>
<td colspan="2">
<strong>Widget instellingen</strong>
<hr size="1" width="100%" color="#333"/>
</td>
</tr>
<?php
for($i = 0; $i < $widgetList->count(); $i++)
{
?>
<tr>
<td class="w150">
<?= $widgetList->item($i)->title ?>
</td>
<td>
<select name="widget_<?= $widgetList->item($i)->id ?>" class="full">
<?php
$itemList = eval($widgetList->item($i)->functionCall);
for($j = 0; $j < $itemList->count(); $j++)
{
$selected = null;
if($_POST["widget_".$widgetList->item($i)->id] == $itemList->item($j)->id)
{
$selected = " selected=\"selected\"";
}
?>
<option value="<?= $itemList->item($j)->id ?>"<?= $selected ?>><?= $itemList->item($j)->title ?></option>
<?php
}
?>
</select>
</td>
</tr>
<?php
}
}
?>
Eval-ed code
public function getNavigationByLanguageId(Integer $parent, ArrayList $objectList, Integer $language)
{
$query = DataAccess::getAdapter()->query("
SELECT *
FROM `navigation`
WHERE `parent_id` = ".$parent->value."
AND `language_id` = ".$language->value."
AND `website_id` = ". $_SESSION["currentSite"]["id"]."
ORDER BY `sort_order`");
while($result = DataAccess::getAdapter()->fetchAssoc($query))
{
$link = new Model_Navigation();
$link->id = $result["id"];
$link->language = $result["language_id"];
$link->parent = $result["parent_id"];
$link->Page = Model_Page::getPageById(new Integer($result["page_id"]));
$link->title = $result["title"];
$link->externalUrl = $result["external_url"];
$link->sortOrder = $result["sort_order"];
$objectList->add($link);
Model_Navigation::getNavigationByLanguageId(new Integer($result["id"]), $objectList, $language);
}
return $objectList;
}
The function being eval-ed is: Model_Navigation::getNavigationByLanguageId(new Integer(0), new ArrayList(), new Integer(7));
Some more explaination about the code I'm using this funcitonality in my new CMS. A user is able to design a template and place widgets in defined regions, pretty much like the portlet functionality jQuery is providing. Widgets are installed for a website by me, I have built in an option to provide a functioncall to retrieve a list of objects when a widget is flagged as 'Selective Content'.
What I'm trying to achieve here is using eval
to return ArrayLists from the value of $widget->functionCall.
I hope it's clear for you, and thanks in advance for the effort you make!
Thanks in advance, Ben