I had already seen and analysed the wiki you recommended (in fact, the lines of code above are from there), which I found interesting and well explained. However, I’d like to know if it’s best for the system to simply write down basic HTML instead of using functions that the server will have to read, understand and run to get to the same basic HTML code that I could’ve written in the first place.
in my opinion, i think the CHtml::xxxx() is good at generating dynamic html content and go well with the
ActiveRecord or FormModel,is mainly used to generate form element , or link (you see you shouldn’t manually to write the url string);
in your above code block , i think if you use the CActiveForm or $model in the same page you 'd better use CHtml helper class , you can get benefit from Chtml class such as client side validate ajax validate,error message display ,etc... if this view do no matter to CActiveForm or $model the BasicHtml way is also ok(for example you don't have a model class for CActiveForm). after all generate html code waste some time <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/smile.gif' class='bbc_emoticon' alt=':)' />
I think you’re right: Plain html should avoid some milliseconds of debugging. But, if I code using CHtml, as a new Yii developer, it’ll take time to learn how to use the class and get used to it, which would be the time a senior Yii developer would save… Anyway, I believe it is worth deep learning how to code with Yii available classes.
I guess I will go for it and start learning/using CHtml. Just hope that everything can be done that way, because it’d be quite frustrating to reach a coding stage in which I’d find myself stuck with simple html elements that cannot be created throw CHtml.
It’s not about using either CHtml or basic HTML, you should use both. Which one depends on the situation. CHtml is great for rendering dynamic Html in cases that the e.g. htmlOptions are passed from function to function before finally being rendered.
Myself I don’t use CHtml::openTag() unless I have htmlOptions that needs to be applied. I also never use CHtml::closeTag() because you don’t have any dynamic data for the closing tag. So it feel unnecessary to call a method for that.
To answer your question, Yii is a rapid application development framework which allows for writing web applications in a very short amount of time. If you find yourself using htmlOptions with basic html, you should instead use CHtml.
Last but not least, CHtml has some methods you can’t live without such as link, label, beginForm, etc. Also, lets not forget that Yii uses the CHtml methods already internally so a few more calls to a static class shouldn’t be worth spending more time on writing view logic.