字段名称 province-en 还是 province_en 对后端操作没有太大的影响,但是把数据传给前端,在操作时就有一个别扭的事情。

前端获取字段值时,含中划线的字段名会提示错误,中划线识别为减号了。
因此joomla5.1中 修改允许包含下划线的字段名就要解决。那在joomla 如何找到这个问题的原因呢?
新增/编辑一个扩展字段,form提交路径:
http://bwg.home.com:8080/administrator/index.php?option=com_fields&context=com_content.article&layout=edit&id=0
根据路径,找到保存提交值的方法save()。
位置如下:
(1)administrator/components/com_fields/src/Model/FieldModel.php
public function save(data)if(!parent::save(data)
if (!parent::save(data)if(!parent::save(data)) {
(2)libraries/src/MVC/Model/AdminModel.php
public function save(data)if(!data)
if (!data)if(!table->check()) {
(3)adminstrator/components/com_fields/src/Table/FieldTable.php
public function check()
this−>name=ApplicationHelper::stringURLSafe(this->name = ApplicationHelper::stringURLSafe(this−>name=ApplicationHelper::stringURLSafe(this->name, $this->language);
(4)libraries/src/Application/ApplicationHelper.php
public static function stringURLSafe($string, $language = ‘’)
output=OutputFilter::stringURLSafe(output = OutputFilter::stringURLSafe(output=OutputFilter::stringURLSafe(string, $language);
(5)libraries/src/Filter/OutputFilter.php
public static function stringURLSafe($string, $language = ‘’)
// Remove any duplicate whitespace, and ensure all characters are alphanumeric
$str = preg_replace(‘/(\s|[^A-Za-z0-9-_])+/’, ‘-’, $str);
//add _ 允许包含下划线
根据数据处理流程,一步步找到了
$str = preg_replace('/(\s|[^A-Za-z0-9\-])+/', '-', $str);
这个正则表达式。
这个正则的意思就是,把str中除大小写字母/数值/中划线保留,其他都转化为中划线。
把这个修改为
$str = preg_replace('/(\s|[^A-Za-z0-9\-\_])+/', '-', $str);
至此就解决了下划线问题。

被折叠的 条评论
为什么被折叠?



