1
我开始开发一个简单的MVC应用程序。我拨打以下功能在我的控制器未定义的属性。无法调用其他页面上的对象属性
public function show()
{
if (!isset($_GET['id']))
return call('pages', 'error');
$ingredient = Ingredients::find($_GET['id']);
require_once('views/ingredients/show.php');
}
我无法访问$ingredient
对象属性,如在show.php$ingredient->item_id
或任何属性。但能够在同一个函数中调用对象属性。
我show.php页面看起来像这样
<p>This is the requested Ingredients:</p>
<p><?php echo $ingredient->item_id; ?></p>
<p><?php echo $ingredient->stock_id; ?></p>
<p><?php echo $ingredient->item_qunatity; ?></p>
<p><?php echo $ingredient->item_unit; ?></p>
我的模型看起来是这样的。这个类的名称是成分
在打印$成分之前,您是否调用show()函数? – Jigar7521
是的。我之前调用过函数。如果我在函数中存储一个变量并在show.php中输出变量,则发生这种情况。 – prithivraj
从$ ingredient = Ingredients :: find($ _ GET ['id'])获取数据后; ,转储$成分,这是给所有的价值?让我知道 – Jigar7521