[英]OctoberCms component: How to display all ID(items) instead of sorting only one ID?
我正在OctoberCms中构建工作申请插件。 现在,只有2个项目中的1个出现在前端。 我想要显示所有项目。 但是现在我只能通过将id输入到组件属性的后端中来选择1
我必须添加此$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(),则会返回一个对象,其中包含每一行的所有值。 您应该遍历它以将它们打印出来。
public function onRender()
{
$object = VacatureModel::where('id', '=', $this -> property('vacatureId')) -> get();
}
foreach($object as $key => $value){ echo $value->id; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.