我正在尝试将新数组项推送到包含数据库项的现有数组变量中.我想要做的是在这个数组的末尾添加一个名为“Others”的新项目,并将其显示为视图中的select下拉列表,其中包含来自数据库的所有项目,并在此末尾选择“其他”项目我手动添加到我的控制器中.
这是我试图做的:
$competition_all = Competition::all();
$newCompete = array('name'=>'Others');
array_push($competition_all, $newCompete);
$this->competition_games = array('Competition');
foreach ($competition_all as $competition_games) {
$this->competition_games[$competition_games->name] = $competition_games->name;
}
它说的是这样的
Unhandled Exception
Message:
Trying to get property of non-object Location:
C:\xampp\htdocs\khelkheladi\khelkheladi\application\controllers\register.php
on line 104
在我的数据库中,竞赛有这种类型的列结构
->id
->year
->place
->name
->created_at
->updated_at
在给定的顺序.
我想要做的是没有实际在数据库中插入项目,只是静态地显示视图中选择标记中的其他选项.如何插入这样的新项目而不将其实际插入数据库但仅在视图中显示?
通过检索数据库项目我之前得到的输出是这样的
Value 1
Value 2
Value 3
Value 4
我喜欢做的就是这样
Value 1
Value 2
Value 3
Value 4
Others