How to add new field ex. website

Questions and answers about change of functions, design, hosting etc.

Moderators: Koduc, Xpycm

Forum rules
Pay attention! Forum is not a means for guaranteed support of clients and users. An answer as well as a quick answer is not supposed on the forum. We post messages as soon as possible.

The message limit on the forum is 3 messages per day.
If you want to say "thank you" then use the function "Give good reputation point", which is a green icon "plus" under the nickname of the person, who answered the message.

How to add new field ex. website

Postby hexcode » 13 Feb 2015, 11:02

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
hexcode
Stranger
 
Posts: 2
Joined: 13 Feb 2015, 10:51
Reputation point: 0

Re: How to add new field ex. website

Postby Koduc » 27 Feb 2015, 09:34

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
-- Меньше знаешь - крепче спишь --
User avatar
Koduc
Team lead
Team lead
 
Posts: 64
Joined: 28 Dec 2011, 09:11
Reputation point: 0

Re: How to add new field ex. website

Postby hexcode » 27 Feb 2015, 17:14

Thank you for detailed help.
Regards
hexcode
Stranger
 
Posts: 2
Joined: 13 Feb 2015, 10:51
Reputation point: 0


Return to Questions and help for changes

Who is online

Users browsing this forum: No registered users and 31 guests

cron