joomla5.1 扩展字段名称不允许包含下划线,把下划线直接转换成了中划线

字段名称 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( d a t a ) i f ( ! p a r e n t : : s a v e ( data) if (!parent::save( data)if(!parent::save(data)) {

(2)libraries/src/MVC/Model/AdminModel.php
public function save( d a t a ) i f ( ! data) if (! data)if(!table->check()) {

(3)adminstrator/components/com_fields/src/Table/FieldTable.php
public function check()
t h i s − > n a m e = A p p l i c a t i o n H e l p e r : : s t r i n g U R L S a f e ( this->name = ApplicationHelper::stringURLSafe( this>name=ApplicationHelper::stringURLSafe(this->name, $this->language);

(4)libraries/src/Application/ApplicationHelper.php
public static function stringURLSafe($string, $language = ‘’)
o u t p u t = O u t p u t F i l t e r : : s t r i n g U R L S a f e ( 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);

至此就解决了下划线问题。

  • 7
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值