php - SilverStripe - Get a page's form value with a function -


in silverstripe 3.1 i'm trying value of hello bar selector accessible pages site wide.

i've created dropdown field select contents on homepage.php i'm having no problem referencing fields value on home page. value of dropdown inform if block run , populate hello bar with.

page.php

..//  public function hellobarselector() {     $selector = homepage::get()->hellobarselect;     return $selector; }  public function showhellobar($itemid = 1) {     $hellobars = hellobar::get()->byid($itemid);     $hellobars = $hellobars->hellobartext;     return $hellobars; }  ..// 

includes/hellobar.ss

<% if $hellobarselector %> <section class="hello">     <p class="hello__text">$showhellobar($hellobarselector)</p> </section> <% end_if %> 

homepage.php

..//  public function getcmsfields(){     $fields = parent::getcmsfields();     $fields->addfieldtotab('root.hellobar', gridfield::create(         'hellobars',         'hello bar text',          $this->hellobars(),         gridfieldconfig_recordeditor::create()     ));     $fields->addfieldtotab('root.hellobar', dropdownfield::create(             'hellobarselect',             'choose hello bar (this sitewide)',             hellobar::get()->map('id', 'hellobartext')         )         ->setemptystring('(none)'));     return $fields; }  ..// 

i have no issues accessing value $hellobarselect on home page , works expected. seems problem accessing $hellobarselect function.

homepage::get() return datalist of homepage dataobjects cant access hellobarselect.

homepage::get()->first() , homepage::get_one() (assuming have 1 homepage there) return 1 dataoject. if field right can use homepage::get()->first()->hellobartext

tip:

use debug::dump(homepage::get()) see manipulating. dump out data see working on.

also read: http://doc.silverstripe.org/en/developer_guides/model/ or watch these videos http://www.silverstripe.org/learn/lessons/


Popular posts from this blog