本文整理汇总了PHP中Companies::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP Companies::validate方法的具体用法?PHP Companies::validate怎么用?PHP Companies::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Companies
的用法示例。
在下文中一共展示了Companies::validate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
/**
* Creates a new model.
* @return create view
*/
public function actionCreate()
{
// check if user has permissions to createCompanies
if (Yii::app()->user->checkAccess('createCompanies')) {
// object models
$model = new Companies();
$address = new Address();
// if Companies form exist and was sent
if (isset($_POST['Companies'])) {
$model->attributes = $_POST['Companies'];
$address->attributes = $_POST['Address'];
// validate models
$valid = $address->validate();
$valid = $model->validate() && $valid;
// validation results
if ($valid) {
// save address
$address->save(false);
$model->address_id = $address->primaryKey;
// save company model
if ($model->save(false)) {
// create object relation and save
$companiesHasUsers = new CompaniesHasUsers();
$companiesHasUsers->company_id = $model->company_id;
$companiesHasUsers->user_id = Yii::app()->user->id;
if ($companiesHasUsers->save(false)) {
// save log
$attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'CompanyCreated', 'log_resourceid' => $model->primaryKey, 'log_type' => Logs::LOG_CREATED, 'user_id' => Yii::app()->user->id, 'module_id' => Yii::app()->controller->id);
Logs::model()->saveLog($attributes);
// to prevent F5 keypress, redirect to view detail page
$this->redirect(array('view', 'id' => $model->company_id));
}
}
}
}
$this->render('create', array('model' => $model, 'address' => $address));
} else {
throw new CHttpException(403, Yii::t('site', '403_Error'));
}
}