This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
You're going to have to be far more specific if you want help. What file and line is the error occurring on? Can we get a screenshot of your stack trace?
.../plugin/authorname/models/xxx.php
public function getMenuOptions()
{
$results = DB::table('benfreke_menumanager_menus')->get();
foreach($results as $val){
$data1[] = $val->id;
$data2[] = $val->title;
}
$data = array_combine($data1,$data2);
return $data;
}
the $data is used by ....../fields.yaml
menu:
label: Menu
type: dropdown
options: getMenuOptions
Firstly, as per the Laravel Queries documentation change that to:
public function getMenuOptions()
{
return DB::table('benfreke_menumanager_menus')->lists('title', 'id');
}
Secondly, the October Form Fields documentation documentation states:
If the options element is omitted, the framework expects a method with the name get*Field*Options() to be defined in the model. Using the example above, the model should have the getStatusOptions() method
You aren't supposed specify an options
line in your fields.yaml
if you want to use your custom method. Just remove it and your code should work.
Last updated
public function getMenuOptions()
{
return $data = DB::table('benfreke_menumanager_menus')->lists('title','id');
}
it is the same error "preg_match(): No ending matching delimiter ']' found"
This is a basic PHP error that you should be able to figure out yourself. I'd say get()
is returning an array, and you're treating it like a PHP object. You should be using lists()
anyway. It's both cleaner and much faster.
" if you want to use your custom method. Just remove it and your code should work. "
" it " means which one
The full quote was
You aren't supposed specify an options line in your fields.yaml if you want to use your custom method. Just remove it and your code should work.
Remove your options: getMenuOptions
line. It's right there in the docs quote I pasted earlier.
o , it works still , now the fields.yaml's code is ...
menu:
label: Menu
type: dropdown
...
the ...xxx.php code is :
public function getMenuOptions()
{
return DB::table('benfreke_menumanager_menus')->lists('title','id');
}
but it still informs the error : preg_match(): No ending matching delimiter ']' found
@freekeywords1817
Try this:
public function getMenuOptions($keyValue = null, $fieldName = null)
{
return ['' => '- None -'] + DB::table('benfreke_menumanager_menus')->lists('title','id');
}
Last updated
@freekeywords1817
The above code worked for me, maybe there's an error elsewhere in your Model ?
In your fields.yaml
place:
menu:
label: Menu
type: dropdown
options: listMenus
and in your Model
use:
public function listMenus($keyValue = null, $fieldName = null)
{
return ['' => '- None -'] + DB::table('benfreke_menumanager_menus')->lists('title','id');
}
This worked for me.
Last updated
yesterday , it could work well when I click "create" button , it can be saved into database table , but today , it showed the error , I don't know why
Still works for me even when I click create
or create & close
. Have you changed anything else in your code?
oh , my God , ok , I give it up , let me build it again ,thank you all for helping me very very much , thank you ,I love you ...
Hi
What feature/extension are you trying to add to the plugin? If you let me know I might be able to help write the code for it?