Create image text field helping prevent information crawing bot.
Field images should be auto created once in first view time, and be removed when data object updated.
Requirements ¶
php_gd
Usage ¶
attach behavior and call to creating in actionView, and removing in actionUpdate.
/* attach behavior */
public function behaviors() {
return array(
'fieldImg' => array(
'class' => 'FieldImgBehavior',
'prefix' => 'c',
'protectFields' => array('address', 'address2', 'tel', 'fax', 'establishment'),
'imgDir' => Yii::app()->params['companyImgFieldsDir'],
),
);
}
/* base image object handle will be company */
$this->setObjBaseDir( $model->company_id );
/* Company's branches address fields with 'branch' model name */
$branches = Branches::model()->findAllByAttributes(array('company_id' => $model->company_id));
$this->genFieldsImage($branches , 'id', 'branch');
...
/* Company's address field with 'default' model name */
$this->genFieldsImage($model, 'company_id');
....
/* remove */
removeAllImgFields( $model->company_id )
...
/* in view.php */
<!-- address of company -->
<?php echo $this->getFieldImageTag('address', $model->company_id); ?>
<!-- address of branches -->
<?php foreach ($branches as $branch): ?>
<?php echo $this->getFieldImageTag('address', $branch->id, 'branch');?>
....
Resources ¶
- [demo] [http://vtown.vn/en/company/saigon-washin-engine.html](http://vtown.vn/en/company/saigon-washin-engine.html "http://vtown.vn/en/company/saigon-washin-engine.html")
Check the address field.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.