Ad
OctoberCms Component: How To Display All ID(items) Instead Of Sorting Only One ID?
I'm building an job application plug-in in OctoberCms. Now only 1 of the 2 items apear on the front-end. I would like all the items to display. But now I can only select 1 by imput the id in the backend at the component propperty
I have to add this$properties = $this->getProperties();
somewhere in my code but I can't figure out where. any suggestions?
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(); } }
Ad
Answer
in the onRender()
you use ->first() at the end. if you change this to ->get() This returns an Object with all values for each row. you should loop through it to print them out ofcourse.
public function onRender()
{
$object = VacatureModel::where('id', '=', $this -> property('vacatureId')) -> get();
}
foreach($object as $key => $value){
echo $value->id;
}
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad