十月cms博客的非英语鼻涕虫



使用October cms的422版本和Rainlab博客插件,不可能有一个非英文的博客文章,每次它都说"slug格式无效"。

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

我建议您按照octobercms的扩展指南进行扩展。这样你就可以安全地更新博客插件,而不必担心再次重新编辑它,或者当你必须重新安装octobercms时,必须记住编辑它。

use RainlabBlogModelsPost;
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;
}
}
}
});
}
}

您可以用类似于模型文件的方式对以下代码进行注释。

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

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

最新更新