OctoberCMS plugin show all the validations at once

后端 未结 3 998
迷失自我
迷失自我 2021-01-24 07:57

I am using Builder plugin to create plugins and did field validations in my model in one of my plugins which works fine.

Let\'s say I have a validation something like t

3条回答
  •  盖世英雄少女心
    2021-01-24 08:21

    Ok Guys, Here is how I resolved this issue.

    Simply go to your plugin which you want to work on and open its Plugin.php file and add following lines of code.

    Plugin.php

    public function boot()
        {
            Event::listen('backend.page.beforeDisplay', function($controller, $action, $params) {
          /* Here you can put your css file wherever you want  .. I put in my current theme's directory */
          $controller->addCss('/themes/your_current_theme_folder_name/assets/css/general.css'); 
            }); 
        }
    

    Done forget to add use Event; before you add your class code in this file.

    Open general.css file and put below code.

    .flash-message.fade.in {
    white-space: pre;
    } 
    

    Next Open plugin's model file and put below code.

    Team.php (Model File)

    public $throwOnValidation = false;
    
    
        public function beforeValidate()
        {
            static $called = false;
            if (!$called) 
            {
                $called = true;
                if (!$this->validate()) 
                {
    
                    throw new \October\Rain\Exception\ValidationException([
                        'Errors' => collect($this->validationErrors)->reduce(function (
                        $msg,
                        $error
                        ) {
                            return $msg . $error[0] . "\r\n"; 
                            })
                    ]);
                }
            }
        }
    

    Hope this helps.

提交回复
热议问题