此问题与更改Page
Title
字段的值时的网址更新功能有关。该行为被编码为 CMSMain.EditForm.js 。
我正在剥离并自定义CMS,以供绝对基本的计算机用户或疏忽的客户端使用,他们很可能在页面名称更改时跳过更新URL 按钮。在这些情况下,如果URLSegment
会自动更新,那将非常方便。
问:自动更新网址段的最简单方法是,点击“更新网址”按钮,之后 模拟结果 更改Title
字段?
答案 0 :(得分:7)
你可以为SiteTree做一个扩展,并像这样包含onBeforeWrite函数。如果他们更新了标题而不是URL,则会进行更改:
rm(list=ls())
cat("\014")
N=4
M = 3
#1. given X matrix N rows and M cols
(x=matrix(c(0.1, 0.2, 0.4, 0.1,0.2,0.7, 0.1, 0.4, 0.7, 0.2, 0.4, 0.7), nrow=N, ncol=M))
#2. calculate the pairwise distance of each pairs abs(x[k,i]-x[k,j]) in each row kth
(xi_xj <- matrix(0, nrow =N, ncol = M, byrow = TRUE))
for (i in 1: N){
xi_xj[i,1] = abs(x[i, 1]-x[i, 2])
xi_xj[i,2] = abs(x[i, 1]-x[i, 3])
xi_xj[i,3] = abs(x[i, 2]-x[i, 3])
}
xi_xj
# 3. In each row, we will need to return the permutation which their value are ordered increasingly.
#create a matrix to store the permutaion or indexing of the increasing order
index_xi_xj = matrix(0, nrow=N, ncol=M)
for (i in 1: N){
#process on each row
(temp <- xi_xj[i,])
#get the index of rearangment in increasing order
index_xi_xj[i,]<- order(temp, decreasing= FALSE)
}
index_xi_xj[4,]
# COMMENT ON THE RESULT:
# PROBLEM comes from the 4th row of the xi_xj[4, ] containing value {0.3, 0.6, 0.3}.
# Once R order them in increasing order, we should have CORRECT permutation {1,3,2}
# of their ordering instead of {3,1,2} as index_xi_xj[4,]
#-------------------------------------------
# 4. test 1: check whether the data in xi_xj[4,1] == xi_xj[4,1] as we see on the console?
xi_xj
if(xi_xj[4,1]==xi_xj[4,3]){
cat("equal")
}else {print ("different")
cat("error = ", xi_xj[4,1]-xi_xj[4,3])
}
# 5. test 2: however, if we order the list of c(0.3, 0.6, 0.3), the function "order()" returns correct permutation {1, 3, 2}
(order(c(0.3, 0.6, 0.3), decreasing=FALSE))
删除&#34; if&#34;意味着它总会被改变。
在class AutoURLSync extends Extension {
public function onBeforeWrite() {
// If Title is changed, but URLSegment is not,
// then update the URLSegment here
if($this->owner->isChanged('Title',2) && !$this->owner->isChanged('URLSegment',2)) {
$this->owner->URLSegment = $this->owner->generateURLSegment($this->owner->Title);
}
}
}
中添加此内容以链接扩展程序:
_config/config.yml