繁体   English   中英

OctoberCms组件:如何显示所有ID(项目),而不是仅排序一个ID?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM