无法在Joomla 3.2中回显对象的单个值 [英] Cannot echo individual values of an object in Joomla 3.2
问题描述
此处遵循本教程: http://docs.joomla.org/Selecting_data_using_JDatabase#Selecting_Records_from_a_Single_Table
following this tutorial here: http://docs.joomla.org/Selecting_data_using_JDatabase#Selecting_Records_from_a_Single_Table
我创建了如下函数:
function getItemForBid() {
// Get a db connection.
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
// Select item record matching the $orderID
$query
->select($db->quoteName(array('id', 'created_by', 'itemtitle', 'deliverydestination', 'listprice')))
->from($db->quoteName('#__entrusters_items'))
->where('id = '.$_GET['orderID']);
// Reset the query using our newly populated query object.
$db->setQuery($query);
// Load the results as a list of stdClass objects (see later for more options on retrieving data).
$db->setQuery($query);
$bidItem = $db->loadObject();
//print_r($bidItem);
}
print_r($bidItem);
工作并返回例如:
stdClass Object (
[id] => 4
[created_by] => 216
[itemtitle] => Tennis Racket
[deliverydestination] => London
[listprice] => 5000
)
但是,如果我尝试回显页面其他位置的值之一,即像这样:
however if I try to echo one of the values elsewhere on the page i.e. like this:
<input name="jform[item_id]" id="jform_item_id" value="<?php echo $bidItem->id; ?> " readonly="" type="text">
我什么也没得到.手册说您可以使用以下方法访问各个值:
I get nothing. The manual says you can access the individual values by using:
$result->index // e.g. $result->email
我在做一些非常愚蠢的事情吗?
Am I doing something very stupid?
推荐答案
$ bidItem对您创建的函数而言是本地的.将它声明为全局文件,以在页面上的其他位置使用它.修改函数的最后几行,例如:
$bidItem is local to the function you created. Declare it as global to use it elsewhere on the page. Modify the last lines of your function like:
global $bidItem;
$bidItem = $db->loadObject();
}
然后在将其用于HTML之前添加:
Then before you use it in your HTML add:
<?php global $bidItem; ?>
这篇关于无法在Joomla 3.2中回显对象的单个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!