本文整理汇总了PHP中Apartment::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Apartment::save方法的具体用法?PHP Apartment::save怎么用?PHP Apartment::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Apartment
的用法示例。
在下文中一共展示了Apartment::save方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
public function actionCreate()
{
if (!Yii::app()->user->isGuest) {
if (Yii::app()->user->checkAccess('backend_access')) {
$this->redirect(Yii::app()->createUrl('/apartments/backend/main/create'));
} else {
$this->redirect(Yii::app()->createUrl('/userads/main/create'));
}
}
if (param('user_registrationMode') == 'without_confirm') {
$user = new User('register_without_confirm');
} else {
$user = new User('register');
}
$login = new LoginForm();
$model = new Apartment();
$model->active = Apartment::STATUS_DRAFT;
$model->period_activity = param('apartment_periodActivityDefault', 'always');
$model->references = $model->getFullInformation($model->id, $model->type);
$isAdmin = false;
$activeTab = 'tab_register';
$isUpdate = Yii::app()->request->getPost('is_update');
if (!$isUpdate && isset($_POST['LoginForm']) && ($_POST['LoginForm']['username'] || $_POST['LoginForm']['password'])) {
if (Yii::app()->user->getState('attempts-login') >= LoginForm::ATTEMPTSLOGIN) {
$login->scenario = 'withCaptcha';
}
$activeTab = 'tab_login';
$login->attributes = $_POST['LoginForm'];
if ($login->validate() && $login->login()) {
Yii::app()->user->setState('attempts-login', 0);
User::updateUserSession();
$isAdmin = Yii::app()->user->checkAccess('backend_access');
$user = User::model()->findByPk(Yii::app()->user->id);
} else {
Yii::app()->user->setState('attempts-login', Yii::app()->user->getState('attempts-login', 0) + 1);
if (Yii::app()->user->getState('attempts-login') >= LoginForm::ATTEMPTSLOGIN) {
$login->scenario = 'withCaptcha';
}
}
}
if (isset($_POST['Apartment'])) {
$model->attributes = $_POST['Apartment'];
if (!$isUpdate) {
$adValid = $model->validate();
$userValid = false;
if ($activeTab == 'tab_register' && param('useUserRegistration')) {
$user->attributes = $_POST['User'];
$userValid = $user->validate();
if ($adValid && $userValid) {
$user->activatekey = User::generateActivateKey();
$userData = User::createUser($user->attributes);
if ($userData) {
$user = $userData['userModel'];
$user->password = $userData['password'];
$user->activatekey = $userData['activatekey'];
$user->activateLink = $userData['activateLink'];
$notifier = new Notifier();
$notifier->raiseEvent('onNewUser', $user, array('forceEmail' => $user->email));
}
}
}
if ($user->id && ($activeTab == 'tab_login' && $adValid || $activeTab == 'tab_register' && param('useUserRegistration') && $adValid && $userValid)) {
if (param('useUseradsModeration', 1)) {
$model->active = Apartment::STATUS_MODERATION;
} else {
$model->active = Apartment::STATUS_ACTIVE;
}
$model->owner_active = Apartment::STATUS_ACTIVE;
$model->owner_id = $user->id;
if ($model->save(false)) {
if (!$isAdmin && param('useUseradsModeration', 1)) {
Yii::app()->user->setFlash('success', tc('The listing is succesfullty added and is awaiting moderation'));
} else {
Yii::app()->user->setFlash('success', tc('The listing is succesfullty added'));
}
if ($activeTab == 'tab_register') {
if (param('user_registrationMode') == 'without_confirm') {
$login = new LoginForm();
$login->setAttributes(array('username' => $user['username'], 'password' => $user['password']));
if ($login->validate() && $login->login()) {
User::updateUserSession();
User::updateLatestInfo(Yii::app()->user->id, Yii::app()->controller->currentUserIp);
$this->redirect(array('/usercpanel/main/index'));
} else {
/*echo 'getErrors=<pre>';
print_r($login->getErrors());
echo '</pre>';
exit;*/
showMessage(Yii::t('common', 'Registration'), Yii::t('common', 'You were successfully registered.'));
}
} else {
showMessage(Yii::t('common', 'Registration'), Yii::t('common', 'You were successfully registered. The letter for account activation has been sent on {useremail}', array('{useremail}' => $user['email'])));
}
} else {
if ($isAdmin) {
NewsProduct::getProductNews();
$this->redirect(array('/apartments/backend/main/update', 'id' => $model->id));
Yii::app()->end();
} else {
$this->redirect(array('/userads/main/update', 'id' => $model->id));
//.........这里部分代码省略.........
示例2: createAction
/**
* Creates a new apartment
* @Route("/create", methods={"POST"}, name="createapartment")
*/
public function createAction()
{
if (!$this->request->isPost()) {
return $this->dispatcher->forward(array("controller" => "apartment", "action" => "index"));
}
$apartment = new Apartment();
$apartment->setCompanyid($this->request->getPost("companyid"));
$apartment->setTowerid($this->request->getPost("towerid"));
$apartment->setName($this->request->getPost("name"));
if (!$apartment->save()) {
foreach ($apartment->getMessages() as $message) {
$this->flash->error($message);
}
return $this->dispatcher->forward(array("controller" => "apartment", "action" => "new"));
}
$this->flash->success("apartment was created successfully");
return $this->dispatcher->forward(array("controller" => "apartment", "action" => "index"));
}
示例3: setApartmentVisitCount
public static function setApartmentVisitCount(Apartment $apartment, $ipAddress = '', $userAgent = '')
{
if (isset($apartment->id) && $apartment->id) {
// total
$apartment->visits += 1;
$apartment->save(false, array('visits'));
// today
Yii::app()->db->createCommand()->insert('{{apartment_statistics}}', array('apartment_id' => $apartment->id, 'date_created' => new CDbExpression('NOW()'), 'ip_address' => $ipAddress, 'browser' => $userAgent));
}
}