fromholdio/silverstripe-externalurlfield 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

fromholdio/silverstripe-externalurlfield

最新稳定版本:2.0.0

Composer 安装命令:

composer require fromholdio/silverstripe-externalurlfield

包简介

Provides SilverStripe with a DBField and FormField for handling external URLs.

README 文档

README

Provides a DBField and FormField for handling external URLs.

Validate and tidy urls as they are captured from users. Configuration is highly flexible. Makes use of php's parse_url and http_build_url to do the actual work.

Installation

Note - this is forked from burnbright/silverstripe-externalurlfield.

composer require fromholdio/silverstripe-externalurlfield "*@stable"

Requirements

Makes use of the http_build_url function from the PECL pecl_http library. However the module's composer requirements include a PHP fallback/shim/polyfill. The composer replacement does check for the presence of http_build_url.

  • SilverStripe ^6

DataObject / Template Usage

Handled by ExternalURL class (Varchar).

use SilverStripe\ORM\DataObject; class MyDataObject extends DataObject { private static $db = array( 'Website' => 'ExternalURL' ); }
<% with $MyDataObject %> <p>Website: $Website</p> <p>Website Nice: $Website.Nice</p> <p>Website Domain: $Website.Domain</p> <p>Website Domain No WWW: $Website.Domain.NoWWW</p> <% end_with %> 

Given the url http://username:password@www.hostname.com:81/path?arg=value#anchor, the above produces:

Website: http://username:password@www.hostname.com:81/path?arg=value#anchor Website Nice: www.hostname.com/path Website Domain: www.hostname.com Website Domain No WWW: hostname.com 

Form Usage

Handled by ExternalURLField (FormField).

Validation is handled by the html5 pattern attribute, and also server side by a more robust regular expression. The field uses the html5 type="url" attribute.

You can configure various parts of the url to be stripped out, or populated with defaults when missing.

use Fromholdio\ExternalURLField\ExternalURLField; //default $websitefield = new ExternalURLField('Website'); //set options (with defaults shown) $websitefield->setConfig(array( //these will be added, if missing 'defaultparts' => array( 'scheme' => 'http' ), //these parts are removed from saved urls 'removeparts' => array( 'scheme' => false, 'user' => true, 'pass' => true, 'host' => false, 'port' => false, 'path' => false, 'query' => false, 'fragment' => false ), 'html5validation' => true )); //say you want to store nice tidy facebook urls $websitefield->setConfig('removeparts',array( 'query' => true, 'fragment' => 'true', 'port' => 'true' )); //a urls like https://www.facebook.com/joe.bloggs?fref=nf&pnref=story //would become https://www.facebook.com/joe.bloggs

HTML5 validation

Enabled by default, the html5 validation sets the field type atribute to url, and adds a pattern attribute which is set to https?://.+.

Disable using the html5validation config:

$field->setConfig("html5validation", false);

Disabling html5 validation is particularly useful if you want to allow users to enter urls that have no scheme/protocol e.g: mywebsite.com instead of http://www.mywebsite.com.

统计信息

  • 总下载量: 29.95k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 6
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 10
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固