This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

freekeywords1817
freekeywords1817

why preg_match(): No ending matching delimiter ']' found , thanks a lot

Flynsarmy
Flynsarmy

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?

freekeywords1817
freekeywords1817

.../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
Flynsarmy
Flynsarmy

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

freekeywords1817
freekeywords1817

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"

Flynsarmy
Flynsarmy

See my edited post above.

freekeywords1817
freekeywords1817

Trying to get property of non-object

the error line is $data1[] = $val->id;

Flynsarmy
Flynsarmy

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.

freekeywords1817
freekeywords1817

" if you want to use your custom method. Just remove it and your code should work. "
" it " means which one

Flynsarmy
Flynsarmy

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.

freekeywords1817
freekeywords1817

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

Daniel81
Daniel81

@freekeywords1817

Try this:

public function getMenuOptions($keyValue = null, $fieldName = null)
{
   return ['' => '- None -'] + DB::table('benfreke_menumanager_menus')->lists('title','id');
}

Last updated

freekeywords1817
freekeywords1817

it still informs the error : preg_match(): No ending matching delimiter ']' found

Daniel81
Daniel81

@freekeywords1817

The above code worked for me, maybe there's an error elsewhere in your Model ?

Daniel81
Daniel81

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

freekeywords1817
freekeywords1817

but , when you click "create" or "create and close" , it shows the error

freekeywords1817
freekeywords1817

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

Daniel81
Daniel81

Still works for me even when I click create or create & close. Have you changed anything else in your code?

freekeywords1817
freekeywords1817

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 ...

benfreke
benfreke

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?

1-20 of 22

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.