Answer the question
In order to leave comments, you need to log in
Yii: How to extend and override a method in CHtml?
Good afternoon! Such a question, there is one class in Yii, it is called CHtml . In particular, I'm interested in the scriptFile method , which generates the html code with the link. of that and that file.
I don't want the tag to be created with type="text/javascript" , and I don't want to make edits in the framework.
Is it possible to somehow extend the CHtml class , and its scriptFile method , so that when CHtml::scriptFIle() is called, my extended method is called?
Method code:
public static function scriptFile($url,array $htmlOptions=array())
{
$defaultHtmlOptions=array(
'type'=>'text/javascript',
'src'=>$url
);
$htmlOptions=array_merge($defaultHtmlOptions,$htmlOptions);
return self::tag('script',$htmlOptions,'');
}
Answer the question
In order to leave comments, you need to log in
and what's the problem?
class MyHtml extends CHtml {
public static function scriptFile($url,array $htmlOptions=array())
{
$defaultHtmlOptions=array(
'src'=>$url
);
$htmlOptions=array_merge($defaultHtmlOptions,$htmlOptions);
return self::tag('script',$htmlOptions,'');
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question