Page 1 of 1

How to add new field ex. website

PostPosted: 13 Feb 2015, 11:02
by hexcode
Hello, i want to add new field 'website' (like text field)in 'apartment ' table.My question where in which file to add code for this new string and display in _tab_general.php like other title,rooms,description etc. (ex. website variable to be accessible like this CHtml::encode($data->website) )


Regards

Re: How to add new field ex. website

PostPosted: 27 Feb 2015, 09:34
by Koduc
Make following steps:
1. Add field to table in database
2. Edit /protected/modules/apartments/models/Apartment.php
2.1. Add to function rules() new array: array('website', 'safe'), or array('website', 'length', 'max' => 255), (this is validation rules)
2.2. Add new line to function attributeLabels(): 'website' => tt('Website', 'apartments'), (this is a 'translation' for this field, you will be able to change it from admin panel)
3. Edit /protected/modules/apartments/views/backend/__form_general.php and add to preferred place:
Code: Select all
<div class="rowold">
    <?php echo $form->labelEx($model'website'); ?>
    <?php echo $form->textField($model'website', array('class' => 'width240')); ?>
    <?php echo $form->error($model'website'); ?>
</div>

4. Add CHtml::encode($data->website) to your _tab_general.php

Re: How to add new field ex. website

PostPosted: 27 Feb 2015, 17:14
by hexcode
Thank you for detailed help.
Regards