本文整理汇总了PHP中Account::setAttributes方法的典型用法代码示例。如果您正苦于以下问题:PHP Account::setAttributes方法的具体用法?PHP Account::setAttributes怎么用?PHP Account::setAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Account
的用法示例。
在下文中一共展示了Account::setAttributes方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
/**
* Logs in the user using the given username and password in the model.
* @return boolean whether login is successful
*/
public function save()
{
$user = new Users();
$user->setAttributes($this->attributes);
$user->setAttribute("password", BaseTool::ENPWD($this->password));
if ($user->validate() && $user->save()) {
$accountarray = array('user_id' => Yii::app()->db->getLastInsertID(), 'total' => 0, 'use_money' => 0, 'no_use_money' => 0, 'newworth' => 0);
$newAccount = new Account();
$newAccount->setAttributes($accountarray);
$newAccount->save();
//发送邮件
$activecode = BaseTool::getActiveMailCode($this->username);
$message = MailTemplet::getActiveEmail($this->username, $activecode);
$mail = Yii::app()->Smtpmail;
$mail->SetFrom(Yii::app()->params['adminEmail']);
$mail->Subject = "好帮贷测试邮件";
$mail->MsgHTML($message);
$mail->AddAddress($this->email);
if ($mail->Send()) {
$user->updateAll(array("regtaken" => $activecode, "regativetime" => time() + 60 * 60), "username=:username", array(":username" => $this->username));
}
Yii::import("application.models.form.LoginForm", true);
$loginform = new LoginForm();
$loginarray = array('rememberMe' => false, 'username' => $this->username, 'password' => $this->password);
$loginform->setAttributes($loginarray);
if ($loginform->validate() && $loginform->login()) {
}
return true;
} else {
$usererror = $user->errors;
$this->addError("username", current(current($usererror)));
return false;
}
}
示例2: testSettingDefaultValueForType
/**
* @depends testValidatesWithoutOwnerWhenSpecifyingAttributesToValidate
*/
public function testSettingDefaultValueForType()
{
$values = array('Prospect', 'Customer', 'Vendor');
$typeFieldData = CustomFieldData::getByName('AccountTypes');
$typeFieldData->serializedData = serialize($values);
$this->assertTrue($typeFieldData->save());
//Add default value to type attribute for account.
$attributeForm = new DropDownAttributeForm();
$attributeForm->attributeName = 'type';
$attributeForm->attributeLabels = array('de' => 'Type', 'en' => 'Type', 'es' => 'Type', 'fr' => 'Type', 'it' => 'Type');
$attributeForm->isAudited = true;
$attributeForm->isRequired = true;
$attributeForm->defaultValueOrder = 2;
$attributeForm->customFieldDataData = $values;
$attributeForm->customFieldDataName = 'AccountTypes';
$modelAttributesAdapterClassName = $attributeForm::getModelAttributeAdapterNameForSavingAttributeFormData();
$adapter = new $modelAttributesAdapterClassName(new Account());
try {
$adapter->setAttributeMetadataFromForm($attributeForm);
} catch (FailedDatabaseSchemaChangeException $e) {
echo $e->getMessage();
$this->fail();
}
$model = new Account();
$this->assertEquals($values[2], $model->type->value);
$user = User::getByUsername('billy');
$_FAKEPOST = array('name' => 'aTestAccount', 'type' => array('value' => $values[1]), 'owner' => array('id' => $user->id));
$model->setAttributes($_FAKEPOST);
$this->assertEquals($values[1], $model->type->value);
$this->assertTrue($model->save());
}
示例3: testEmptyPostValueSavingAsZeros
/**
* @depends testBulkSetAndGetWithRelatedModels
*/
public function testEmptyPostValueSavingAsZeros()
{
Yii::app()->user->userModel = User::getByUsername('super');
$_FAKEPOST = array('Account' => array('name' => 'Vomitorio Corp 2', 'officePhone' => '123456789', 'officeFax' => '', 'employees' => 3, 'annualRevenue' => null, 'website' => 'http://barf.com', 'billingAddress' => array('street1' => '123 Road Rd', 'street2' => null, 'city' => 'Cityville', 'postalCode' => '12345', 'country' => 'Countrilia'), 'description' => 'a description'));
$user = User::getByUsername('bobby');
$account = new Account();
$account->owner = $user;
$account->setAttributes($_FAKEPOST['Account']);
$this->assertTrue($account->save());
$account = Account::getById($account->id);
$this->assertEmpty($account->officeFax);
$this->assertNotSame(0, $account->officeFax);
$this->assertNotSame(0, $account->billingAddress->street2);
}
示例4: addUser
public static function addUser($weixinUser)
{
#注册新用户
$newuser = new Users();
$newuser->setAttribute('username', $weixinUser);
$newuser->setAttribute('password', 'ooxxooxx');
$newuser->setAttribute('wangwang', $weixinUser);
$newuser->setAttribute('privacy', uniqid());
if ($newuser->validate() && $newuser->save()) {
$accountarray = array('user_id' => Yii::app()->db->getLastInsertID(), 'total' => 0, 'use_money' => 0, 'no_use_money' => 0, 'newworth' => 0);
$newAccount = new Account();
$newAccount->setAttributes($accountarray);
$newAccount->save();
}
$user = Users::model()->find("username=:username", array(":username", $weixinUser));
return $user;
}
示例5: testSearch
/**
* @depends testMakeWhereAndGetSubset
*/
public function testSearch()
{
Yii::app()->user->userModel = User::getByUsername('super');
$_FAKEPOST = array('Account1' => array('name' => 'Vomitorio Corp', 'officePhone' => '123456789', 'officeFax' => null, 'employees' => 123, 'annualRevenue' => null, 'website' => 'http://barf.com', 'billingAddress' => array('street1' => '123 Road Rd', 'street2' => null, 'city' => 'Cityville', 'postalCode' => '12345', 'country' => 'Countralia'), 'description' => 'a description'), 'Account2' => array('name' => 'Victorinox', 'officePhone' => '987654321', 'officeFax' => '55566666', 'employees' => 123, 'annualRevenue' => null, 'website' => 'http://www.victorinox.com', 'description' => 'A pretty sharp bunch.'));
$user = User::getByUsername('billy');
$account1 = new Account();
$account1->owner = $user;
$account1->setAttributes($_FAKEPOST['Account1']);
$this->assertTrue($account1->save());
$account2 = new Account();
$account2->owner = $user;
$account2->setAttributes($_FAKEPOST['Account2']);
$this->assertTrue($account2->save());
$_FAKEPOST = array('Account' => array('name' => 'Vomitorio Corp', 'officePhone' => null, 'officeFax' => null, 'employees' => null, 'annualRevenue' => null, 'website' => null, 'billingAddress' => array('street1' => null, 'street2' => null, 'city' => null, 'postalCode' => null, 'country' => null), 'description' => null));
$metadataAdapter = new SearchDataProviderMetadataAdapter(new Account(false), 1, $_FAKEPOST['Account']);
$searchAttributeData = $metadataAdapter->getAdaptedMetadata();
$dataProvider = new RedBeanModelDataProvider('Account', 'name', false, $searchAttributeData);
$accounts = $dataProvider->getData();
$this->assertEquals(1, count($accounts));
$this->assertEquals(1, $dataProvider->calculateTotalItemCount());
$_FAKEPOST['Account']['officePhone'] = '123456';
$metadataAdapter = new SearchDataProviderMetadataAdapter(new Account(false), 1, $_FAKEPOST['Account']);
$searchAttributeData = $metadataAdapter->getAdaptedMetadata();
$dataProvider = new RedBeanModelDataProvider('Account', 'name', false, $searchAttributeData);
$accounts = $dataProvider->getData();
$this->assertEquals(1, count($accounts));
$this->assertEquals(1, $dataProvider->calculateTotalItemCount());
$_FAKEPOST['Account']['officePhone'] = '5551234567';
$metadataAdapter = new SearchDataProviderMetadataAdapter(new Account(false), 1, $_FAKEPOST['Account']);
$searchAttributeData = $metadataAdapter->getAdaptedMetadata();
$dataProvider = new RedBeanModelDataProvider('Account', 'name', false, $searchAttributeData);
$accounts = $dataProvider->getData();
$this->assertEquals(0, count($accounts));
$this->assertEquals(0, $dataProvider->calculateTotalItemCount());
$_FAKEPOST['Account']['name'] = null;
$_FAKEPOST['Account']['officePhone'] = null;
$_FAKEPOST['Account']['billingAddress']['country'] = null;
$_FAKEPOST['Account']['employees'] = 123;
$metadataAdapter = new SearchDataProviderMetadataAdapter(new Account(false), 1, $_FAKEPOST['Account']);
$searchAttributeData = $metadataAdapter->getAdaptedMetadata();
$dataProvider = new RedBeanModelDataProvider('Account', 'name', false, $searchAttributeData);
$accounts = $dataProvider->getData();
$this->assertEquals(2, count($accounts));
$this->assertEquals(2, $dataProvider->calculateTotalItemCount());
$_FAKEPOST['Account']['employees'] = 124;
$metadataAdapter = new SearchDataProviderMetadataAdapter(new Account(false), 1, $_FAKEPOST['Account']);
$searchAttributeData = $metadataAdapter->getAdaptedMetadata();
$dataProvider = new RedBeanModelDataProvider('Account', 'name', false, $searchAttributeData);
$accounts = $dataProvider->getData();
$this->assertEquals(0, count($accounts));
$this->assertEquals(0, $dataProvider->calculateTotalItemCount());
$_FAKEPOST['Account']['name'] = 'V';
$_FAKEPOST['Account']['employees'] = 123;
$metadataAdapter = new SearchDataProviderMetadataAdapter(new Account(false), 1, $_FAKEPOST['Account']);
$searchAttributeData = $metadataAdapter->getAdaptedMetadata();
$dataProvider = new RedBeanModelDataProvider('Account', 'name', false, $searchAttributeData);
$accounts = $dataProvider->getData();
$this->assertEquals(2, count($accounts));
$this->assertEquals(2, $dataProvider->calculateTotalItemCount());
}