OctoberCms 组件:如何显示所有 ID(项目)而不是仅对一个 ID 进行排序?
OctoberCms component: How to display all ID(items) instead of sorting only one ID?
我正在 OctoberCms 中构建工作申请插件。现在只有 2 项中的 1 项出现在前端。我想要显示所有项目。但是现在我只能 select 1 通过在组件属性
的后端输入 id
我必须在我的代码中的某处添加这个$properties = $this->getProperties();
,但我不知道在哪里。有什么建议吗?
php namespace Hessel\Vacatures\Components;
use Cms\Classes\ComponentBase;
use Hessel\Vacatures\Models\Vacature as VacatureModel;
class vacature extends ComponentBase
{
public function componentDetails()
{
return [
'name' => 'Vacature Component',
'description' => 'No description provided yet...'
];
}
public function defineProperties()
{
return [
'vacatureId' => [
'title' => 'Vacature'
],
];
}
public function getVacatureIdOptions()
{
return VacatureModel::select('id', 'title')->orderBy('title')->get()->lists('title', 'id');
}
public function onRender()
{
$this->vacature = $this->page['vacature'] = VacatureModel::where('id', '=', $this -> property('vacatureId')) -> first();
}
}
在 onRender()
最后使用 ->first() 。如果将其更改为 ->get() This returns 一个包含每行所有值的对象。你应该遍历它以将它们打印出来。
public function onRender()
{
$object = VacatureModel::where('id', '=', $this -> property('vacatureId')) -> get();
}
foreach($object as $key => $value){
echo $value->id;
}
我正在 OctoberCms 中构建工作申请插件。现在只有 2 项中的 1 项出现在前端。我想要显示所有项目。但是现在我只能 select 1 通过在组件属性
的后端输入 id我必须在我的代码中的某处添加这个$properties = $this->getProperties();
,但我不知道在哪里。有什么建议吗?
php namespace Hessel\Vacatures\Components; use Cms\Classes\ComponentBase; use Hessel\Vacatures\Models\Vacature as VacatureModel; class vacature extends ComponentBase { public function componentDetails() { return [ 'name' => 'Vacature Component', 'description' => 'No description provided yet...' ]; } public function defineProperties() { return [ 'vacatureId' => [ 'title' => 'Vacature' ], ]; } public function getVacatureIdOptions() { return VacatureModel::select('id', 'title')->orderBy('title')->get()->lists('title', 'id'); } public function onRender() { $this->vacature = $this->page['vacature'] = VacatureModel::where('id', '=', $this -> property('vacatureId')) -> first(); } }
在 onRender()
最后使用 ->first() 。如果将其更改为 ->get() This returns 一个包含每行所有值的对象。你应该遍历它以将它们打印出来。
public function onRender()
{
$object = VacatureModel::where('id', '=', $this -> property('vacatureId')) -> get();
}
foreach($object as $key => $value){
echo $value->id;
}