Hi guys,
I’m thinking of switching to Yii after 8 years of adodb (AR) + smarty + my own custom MVC and I’m having trouble grasping some concepts. First of all I don’t like the usage of OOP to generate form fields in Yii views and was wondering if it is possible not tu use them but still have the functionality needed?
For example this is the default code from Yii:
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'contact-form',
'enableClientValidation'=>true,
'clientOptions'=>array(
'validateOnSubmit'=>true,
),
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'name'); ?>
<?php echo $form->textField($model,'name'); ?>
<?php echo $form->error($model,'name'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'email'); ?>
<?php echo $form->textField($model,'email'); ?>
<?php echo $form->error($model,'email'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'subject'); ?>
<?php echo $form->textField($model,'subject',array('size'=>60,'maxlength'=>128)); ?>
<?php echo $form->error($model,'subject'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'body'); ?>
<?php echo $form->textArea($model,'body',array('rows'=>6, 'cols'=>50)); ?>
<?php echo $form->error($model,'body'); ?>
</div>
<?php if(CCaptcha::checkRequirements()): ?>
<div class="row">
<?php echo $form->labelEx($model,'verifyCode'); ?>
<div>
<?php $this->widget('CCaptcha'); ?>
<?php echo $form->textField($model,'verifyCode'); ?>
</div>
<div class="hint">Please enter the letters as they are shown in the image above.
<br/>Letters are not case-sensitive.</div>
<?php echo $form->error($model,'verifyCode'); ?>
</div>
<?php endif; ?>
<div class="row buttons">
<?php echo CHtml::submitButton('Submit'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
and this to me is definitly NOT separation of logic and design. Give that “template” code to a designer in your company and see if he can change the design. Ain’t gonna happen. Also as a programmer you then have to “translate” his design to PHP code that will eventually again generate that same design!? Even 7 or 8 years back I was avoding the usage of HTML/form generating OOP classes in PHP. So what I’m wondering is - will the posted code work if I replace
<?php echo $form->textField($model,'name'); ?>
and
<?php echo $form->textArea($model,'body',array('rows'=>6, 'cols'=>50)); ?>
with actual HTML code? Would that change anything regarding Yii functionality? I’m ok with the form header being done by Yii (not thrilled but ok).
Second question. How to get Yii to understand SEO links in this formats:
www.domain.com/product/name_of_the_product.html ("product" is a static word)
or
www.domain.com/group_name/sub_group/sub_group_id
or
www.domain.com/contact_us.html
www.domain.com/about_us.html
with all being ofcourse dynamic PHP pages…
Third question. If i understood Yii than my Poll should be a widget right?What’s the difference between module and a widget?