我和你有同样的问题。
修补以下文件:
/path/to/yii/framework/web/helpers/CHtml.php
找到方法“resolveName”,将其替换为以下内容:
/**
* Resolves a class name, removing namespaces.
*/
public static function resolveClassName($model){
return end(explode('\\',get_class($model)));
}
/**
* Generates input name for a model attribute.
* Note, the attribute name may be modified after calling this method if the name
* contains square brackets (mainly used in tabular input) before the real attribute name.
* @param CModel $model the data model
* @param string $attribute the attribute
* @return string the input name
*/
public static function resolveName($model,&$attribute)
{
if(($pos=strpos($attribute,'['))!==false)
{
if($pos!==0) // e.g. name[a][b]
return self::resolveClassName($model).'['.substr($attribute,0,$pos).']'.substr($attribute,$pos);
if(($pos=strrpos($attribute,']'))!==false && $pos!==strlen($attribute)-1) // e.g. [a][b]name
{
$sub=substr($attribute,0,$pos+1);
$attribute=substr($attribute,$pos+1);
return self::resolveClassName($model).$sub.'['.$attribute.']';
}
if(preg_match('/\](\w+\[.*)$/',$attribute,$matches))
{
$name=self::resolveClassName($model).'['.str_replace(']','][',trim(strtr($attribute,array(']['=>']','['=>']')),']')).']';
$attribute=$matches[1];
return $name;
}
}
return self::resolveClassName($model).'['.$attribute.']';
}
希望这可以帮助!
PS 对于任何认为这是愚蠢或不必要的人,客户端验证器不起作用,因为您无法使用 JavaScript(或至少使用 jQuery)通过 ID 选择带有反斜杠的元素