十月cms博客的非英语slug

3

使用 10 月 cms 的构建版本 422 和 Rainlab 博客插件,不可能拥有非英语音节的博客文章别名,每次都会显示 "别名格式无效"。

是否有解决方案或方法来解决这个限制?

2个回答

2
你可以像下面这样在模型文件中对代码进行注释。
路径 :: Plugins/rainlab/blog/models/Post.php
 public $rules = [
        'title' => 'required',
        // 'slug' => ['required', 'regex:/^[a-z0-9\/\:_\-\*\[\]\+\?\|]*$/i', 'unique:rainlab_blog_posts'],
        'content' => 'required',
        'excerpt' => ''
    ];

1
我认为唯一需要注释掉的是regex部分? - Wreigh
谢谢,它起作用了,但我只是从slug验证中删除了正则表达式部分。 - Amin
@ Wreigh 是的,我们可以做到这一点。 - AddWeb Solution Pvt Ltd

2
我建议您按照octobercms的扩展指南进行扩展。这样,您就可以安全地更新博客插件,而不必担心重新编辑它,或者在重新安装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;
                     }
                 }
            }
        });
    }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接