October CMS : Not able to create a Form Widget

僤鯓⒐⒋嵵緔 提交于 2021-02-07 17:24:24

问题


I'm new to October CMS and learning to create a Form Widget. But I'm getting the following error :

The partial '_field_actorbox.htm' is not found.
/opt/lampp/htdocs/octobermovies/modules/system/traits/ViewMaker.php line 65

My widget folder name is 'formwidgets' My partials file name inside partials folder is '_widget.htm' Content of my formwidgets > Actorbox.php

namespace Watchlearn\Movies\FormWidgets;

use Backend\Classes\FormWidgetBase;
use Config;

class ActorBox extends FormWidgetBase
{
    public function widgetDetails()
    {
        return [
            'name' => 'Actorbox',
            'description' => 'Field for adding actors'
        ];
    }

    public function render(){
        return $this->makePartial('widget');
    }

    public function loadAssets()
    {
        $this->addCss('css/select2.css');
        $this->addJs('js/select2.js');
    }
}

My code to register the widget in plugin.php

public function registerFormWidgets()
    {
        return [
            'Watchlearn\Movies\FormWidgets\ActorBox' => [
                'label' => 'ActorBox Field',
                'code' => 'actorbox'
            ]
        ];
    }

I tried to find and looked into the documentation also but could not find any solution for this.


回答1:


The Actorbox.php should be in the formwidgets path. If properly created the dir structure would be like

|-- formwidgets
|  
|-- ActorBox.php
|   `-- actorbox
|       |-- assets
|       |   |-- css
|       |   |   |-- actorbox.css
|       |   |   `-- select2.min.css
|       |   `-- js
|       |       |-- actorbox.js
|       |       `-- select2.min.js
|       `-- partials
|           `-- _actorbox.htm



回答2:


did you created your formwidget files using artisan ?

php artisan create:formwidget watchlearn\Movies Tagbox (into the plugin folder)

Maybe it will help you set the correct permissions and help you out :) (it did for me, I had exactly the same issue)




回答3:


I think the error lies here:

My widget folder name is 'formwidgets' My partials file name inside partials folder is '_widget.htm' Content of my formwidgets > Actorbox.php

But then you have

class ActorBox extends FormWidgetBase

and you seem to use that classname with the uppercase B throughout the rest of the code.

OctoberCMS is looking for the file formWidgets/ActorBox.php, matching the classname given in the registerFormWidgets function. FormWidget (and Component and Model and etc.) .php file names should always match the contained Widget (or whatever the case) class names with the exact same case.

So in this case, the form widget is simply not registered, because no file with the matching name is found. The field of type: actorbox in the form definition .yaml file you are using is then by default causing October to look for a _field_actorbox.htm partial to be rendered.

So just rename your Actorbox.php to ActorBox.php and your problem should be solved, I hope.




回答4:


Try to check your path of your file actorbox.php. I got the same issues as well, I moved my actorbox.php to the correct path then everything works fine.



来源:https://stackoverflow.com/questions/40493997/october-cms-not-able-to-create-a-form-widget

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!