Php OctoberCms组件:如何显示所有ID(项目),而不是只排序一个ID?
我正在十月CMS中构建一个工作应用程序插件。现在前端只有两个项目中的一个出现了。我想展示所有的物品。但是现在我只能通过在组件属性的后端输入id来选择1 我必须添加这个Php OctoberCms组件:如何显示所有ID(项目),而不是只排序一个ID?,php,plugins,octobercms,Php,Plugins,Octobercms,我正在十月CMS中构建一个工作应用程序插件。现在前端只有两个项目中的一个出现了。我想展示所有的物品。但是现在我只能通过在组件属性的后端输入id来选择1 我必须添加这个$properties=$this->getProperties()在我的代码中的某个地方,但我不知道在哪里。有什么建议吗 php namespace Hessel\Vacatures\Components; use Cms\Classes\ComponentBase; use Hessel\Vacatures\Models\Va
$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();
}
}
php名称空间Hessel\Vacations\Components;
使用Cms\Classes\ComponentBase;
使用Hessel\Vacations\Models\Vacation作为VacationModel;
类休假扩展了ComponentBase
{
公共功能组件详细信息()
{
返回[
“名称”=>“假期组件”,
“说明”=>“尚未提供说明…”
];
}
公共功能定义属性()
{
返回[
“度假ID”=>[
“标题”=>“假期”
],
];
}
公共函数GetVacationIdoOptions()
{
return vacationmodel::select('id','title')->orderBy('title')->get()->list('title','id');
}
公共函数onRender()
{
$this->vacuure=$this->page['vacuure']=vacuuremodel::where('id','=',$this->property('vacuureid'))->first();
}
}
在onRender()
中,在末尾使用->first()。如果将其更改为->get(),则会返回一个包含每行所有值的对象。当然,您应该循环使用它来打印它们
public function onRender()
{
$object = VacatureModel::where('id', '=', $this -> property('vacatureId')) -> get();
}
foreach($key=>value的对象){
echo$value->id;
}
你能给我一个循环的例子吗?tnx的帮助=如果答案是正确的,请标记它,以便进一步的读者可以发现它!欢迎光临!