Long term would it not be better if Yii core changed CHtml to some sort of Composite class patter. Where there are formatter classes that can be set as a setting and if nothing is set the default Yii core formatter class would be used. Long term this way we could support different doc types and standards IE: xhtml vs html5 and developers can customise the output of CHtml. CHtml is a static class/methods. I am not experienced enough to say what would be a good or bad architecture or how that would affect our options.
I am a little new to OOP and Yii, but from what I have learnt so far that sounds like something that could work.
How to override Yii core classes An example with CHtml that demonstrates how to override core classes
#22
Posted 26 March 2012 - 03:32 PM
NaX, on 22 March 2012 - 06:40 AM, said:
Long term would it not be better if Yii core changed CHtml to some sort of Composite class patter. Where there are formatter classes that can be set as a setting and if nothing is set the default Yii core formatter class would be used. Long term this way we could support different doc types and standards IE: xhtml vs html5 and developers can customise the output of CHtml. CHtml is a static class/methods. I am not experienced enough to say what would be a good or bad architecture or how that would affect our options.
That's what i expect from Yii 2.0, too. But meanwhile we need to deal with Yii 1.x and that's what the workaround is for. In 2.0 i'd like to see a pluggable CHtml class for bootstrap, foundation or any other CSS library.
#23
Posted 21 May 2013 - 03:40 AM
shailesh, on 22 March 2012 - 04:47 AM, said:
We Are Doing In These Way
STEP 1 ) Copy CHtml.php into protected/components/Html.php
STEP 2 ) Create CHtml.php under protected/components and extend it from Html class.
STEP 3) When the new Yii version is released, update Html.php
STEP 1 ) Copy CHtml.php into protected/components/Html.php
STEP 2 ) Create CHtml.php under protected/components and extend it from Html class.
STEP 3) When the new Yii version is released, update Html.php
Hi, I did just like you said here but it doesn't seem to work, do you have something in your config file ?
'import'=>array( 'application.models.*', 'application.components.*', 'application.extentions.*', 'application.helpers.*', ),
#24
Posted 21 May 2013 - 06:03 AM
Yes, you have to import your class. Please read my first post again carefully.
#25
Posted 30 May 2013 - 01:39 AM
Mike, on 21 May 2013 - 06:03 AM, said:
Yes, you have to import your class. Please read my first post again carefully.
'application.components.CHtml',
Yes, I didn't add this line of code in the import, because I thought that 'application.components.*', will do the job. But I ended up not using this method because I don't want to update that file every time, and some errors might come up somewhere.
#26
Posted 30 May 2013 - 06:15 AM
I actually quite like the idea of cloning and merging the Yii framework repository. If you simply added a namespace to the core CHtml class and made no other changes, then you'd never have to deal with merge conflicts. You could then write your own globally namespaced CHtml class and extend the core class directly within your projects in the way you're already suggesting.
I don't see any real downsides to that; it just means that the cloned version of the framework will only be useable in projects where you've overridden CHtml.
I don't see any real downsides to that; it just means that the cloned version of the framework will only be useable in projects where you've overridden CHtml.

Help













