php - Laravel backpack select_from_array -


i totally confused select_from_array field in laravel backpack.

in controller using select_from_array field in options call function,but when run code error displayed. please me this.

error : fatalerrorexception in eventcontroller.php line 106: syntax error, unexpected '$this' (t_variable)

controller.php

public $crud = array(     "model" => "app\larapen\models\event",     "entity_name" => "event",     "entity_name_plural" => "events",     "route" => "admin/event",     "reorder" => true,     "reorder_label" => "name",     "reorder_max_level" => 2,     "details_row" => true,      // *****     // columns     // *****     "columns" => [         [             'name' => "id",             'label' => "id"         ],   ], "fields" => [              [                 'name' => "event_name",                 'label' => "event name",                 'type' => "text",                 'placeholder' => "event name",             ],             [                 'name' => "event_topic",                 'label' => "event topic",                 'type' => "text",                 'placeholder' => "event topic",             ],             [                 'name' => "event_type_id",                 'label' => "event type",                 'model' => "app\larapen\models\eventtype",                 'entity' => "eventtype",                 'attribute' => "name",                 'type' => "select",             ],              [                 'name' => "about_event",                 'label' => "about event",                 'type' => "ckeditor",                 'placeholder' => "about event",             ],             [                 'name' => "country_code",                 'label' => "country",                 'type' => 'select_from_array',                 'options' => $this->countries(),                 'allows_null' => false,              ],      ], );     public function countries()   {       ..................   } 

please me , why happens? how solve issue? waiting response................

you can not use pseudo-variable $this out of class method.

http://php.net/manual/en/language.oop5.properties.php

the pseudo-variable $this available inside class method when method called within object context. $this reference calling object

so if want set attribute of crud's $this, can set in __construct function

public function __construct() {     $this->crud['fields'][4] = $this->countries(); } 

or initialize __construct function

public $crud;  public function __construct() {     $this->crud = array(                         'model' => 'app\larapen\models\event',                         'entity_name' => 'event',                         'entity_name_plural' => 'events',                         'route' => 'admin/event',                         'reorder' => true,                         'reorder_label' => 'name',                         'reorder_max_level' => 2,                         'details_row' => true,                          // *****                         // columns                         // *****                         'columns' => [                             [                                 'name' => 'id',                                 'label' => 'id'                             ],                         ],                         'fields' => [                                      [                                         'name' => 'event_name',                                         'label' => 'event name',                                         'type' => 'text',                                         'placeholder' => 'event name',                                     ],                                     [                                         'name' => 'event_topic',                                         'label' => 'event topic',                                         'type' => 'text',                                         'placeholder' => 'event topic',                                     ],                                     [                                         'name' => 'event_type_id',                                         'label' => 'event type',                                         'model' => 'app\larapen\models\eventtype',                                         'entity' => 'eventtype',                                         'attribute' => 'name',                                         'type' => 'select',                                     ],                                      [                                         'name' => 'about_event',                                         'label' => 'about event',                                         'type' => 'ckeditor',                                         'placeholder' => 'about event',                                     ],                                     [                                         'name' => 'country_code',                                         'label' => 'country',                                         'type' => 'select_from_array',                                         'options' => $this->countries(),                                         'allows_null' => false,                                      ],                              ],                         );     } 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -