十月 cms 博客的非英语 slug

Non English slug for October cms blog

使用 October cms build 422 和 Rainlab 博客插件,不可能有非英语的博客 post,每次都说 "The slug format is invalid."

是否有解决此限制的解决方案或解决方法?

您可以在您的模型文件中对以下代码进行评论。

路径:: Plugins/rainlab/blog/models/Post.php

 public $rules = [
        'title' => 'required',
        // 'slug' => ['required', 'regex:/^[a-z0-9\/\:_\-\*\[\]\+\?\|]*$/i', 'unique:rainlab_blog_posts'],
        'content' => 'required',
        'excerpt' => ''
    ];

我建议您遵循 extending guide of octobercms 并扩展它。 这样你就可以安全地更新博客插件,而不必担心再次重新编辑它,或者当你必须重新安装 octobercms 时不得不记住编辑它。

use Rainlab\Blog\Models\Post;

class Plugin extends PluginBase 
{
    public function boot()
    { 
        // Extend post Model
        Post::extend(function($model) {
            // Only do stuff when validation is triggered
            $model->bindEvent('model.beforeValidate', function() use ($model) {
                 // Find the regex holding value to avoid hardcoding array index
                 foreach($model->rules as $key => $value) {
                     if(strpos($value, 'regex:') !== false) {
                          // unset validation rule containing the regex.
                          unset($model->rules[$key]);
                          break;
                     }
                 }
            }
        });
    }
}