Sorry, here’s the code. Let me know if you need any other code snippet. I really appreciate it.
_form.php:
<?php
/* @var $this TenantController */
/* @var $model TTenant */
/* @var $form CActiveForm */
?>
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'ttenant-form',
// Please note: When you enable ajax validation, make sure the corresponding
// controller action is handling ajax validation correctly.
// There is a call to performAjaxValidation() commented in generated controller code.
// See class documentation of CActiveForm for details on this.
'enableAjaxValidation'=>false,
)); ?>
<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,'dbu'); ?>
<?php echo $form->textField($model,'dbu',array('size'=>16,'maxlength'=>16)); ?>
<?php echo $form->error($model,'dbu'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'e_dbpwd'); ?>
<?php echo $form->textField($model,'e_dbpwd',array('size'=>60,'maxlength'=>1024)); ?>
<?php echo $form->error($model,'e_dbpwd'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'business_name'); ?>
<?php echo $form->textField($model,'business_name',array('size'=>60,'maxlength'=>128)); ?>
<?php echo $form->error($model,'business_name'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'is_dedicated'); ?>
<?php echo $form->textField($model,'is_dedicated'); ?>
<?php echo $form->error($model,'is_dedicated'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'member_type'); ?>
<?php echo $form->textField($model,'member_type'); ?>
<?php echo $form->error($model,'member_type'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
TTenant.php
<?php
/**
* This is the model class for table "tenant".
*
* The followings are the available columns in table 'tenant':
* @property string $id
* @property string $dbu
* @property string $e_dbpwd
* @property string $business_name
* @property integer $is_dedicated
* @property integer $member_type
*
* The followings are the available model relations:
* @property User[] $user
*/
class TTenant extends CActiveRecord
{
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'tenant';
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('dbu, e_dbpwd, business_name', 'required'),
array('is_dedicated, member_type', 'numerical', 'integerOnly'=>true),
//array('id', 'length', 'max'=>10),
array('dbu', 'length', 'max'=>16, 'safe'),
array('e_dbpwd', 'length', 'max'=>1024, 'safe'),
array('business_name', 'length', 'max'=>128),
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('id, dbu, e_dbpwd, business_name, is_dedicated, member_type', 'safe', 'on'=>'search'),
);
}
/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'user' => array(self::HAS_MANY, 'TUser', 'tenant_id')
);
}
public function beforeSave()
{
if ($this->isNewRecord) {
Common::createMySQLUser($this->dbu,$this->e_dbpwd);
}
return parent::beforeSave();
}
public function getListOfAllTenants() // used only by app staff to assign users to tenants
{
$criteria = new CDbCriteria(array(
'select'=>'id, business_name',
'order'=>'business_name ASC',
));
$listOfAllTenants=CHtml::listData($this->findAll($criteria), 'id', 'business_name');
return $listOfAllTenants;
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id' => 'Primary key',
'dbu' => 'Usuario BD',
'e_dbpwd' => 'Contraseña BD',
'business_name' => 'Nombre negocio',
'is_dedicated' => 'BD dedicada',
'member_type' => 'Tipo miembro',
);
}
/**
* Retrieves a list of models based on the current search/filter conditions.
*
* Typical usecase:
* - Initialize the model fields with values from filter form.
* - Execute this method to get CActiveDataProvider instance which will filter
* models according to data in model fields.
* - Pass data provider to CGridView, CListView or any similar widget.
*
* @return CActiveDataProvider the data provider that can return the models
* based on the search/filter conditions.
*/
public function search()
{
// @todo Please modify the following code to remove attributes that should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id,true);
$criteria->compare('dbu',$this->dbu,true);
$criteria->compare('e_dbpwd',$this->e_dbpwd,true);
$criteria->compare('business_name',$this->business_name,true);
$criteria->compare('is_dedicated',$this->is_dedicated);
$criteria->compare('member_type',$this->member_type);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
/**
* Returns the static model of the specified AR class.
* Please note that you should have this exact method in all your CActiveRecord descendants!
* @param string $className active record class name.
* @return TTenant the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
}
create.php
<?php
/* @var $this TenantController */
/* @var $model TTenant */
$this->breadcrumbs=array(
'Ttenants'=>array('index'),
'Create',
);
$this->menu=array(
array('label'=>'List TTenant', 'url'=>array('index')),
array('label'=>'Manage TTenant', 'url'=>array('admin')),
);
?>
<h1>Create TTenant</h1>
<?php $this->renderPartial('_form', array('model'=>$model)); ?>