当前位置: 首页>>代码示例>>PHP>>正文


PHP Contacts::setAttributes方法代码示例

本文整理汇总了PHP中Contacts::setAttributes方法的典型用法代码示例。如果您正苦于以下问题:PHP Contacts::setAttributes方法的具体用法?PHP Contacts::setAttributes怎么用?PHP Contacts::setAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Contacts的用法示例。


在下文中一共展示了Contacts::setAttributes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testDisableAutomaticRecordTagging

 public function testDisableAutomaticRecordTagging()
 {
     Yii::app()->db->createCommand("delete from x2_tags where 1");
     $admin = Yii::app()->settings;
     $admin->disableAutomaticRecordTagging = true;
     $this->assertUpdates($admin, array('disableAutomaticRecordTagging'));
     $contact = new Contacts();
     $contact->setAttributes(array('firstName' => 'test', 'lastName' => 'test', 'visibility' => 1, 'backgroundInfo' => '#tag0 #tag1 #tag2'));
     $this->assertSaves($contact);
     $this->assertEquals(0, (int) Yii::app()->db->createCommand("\n            select count(*) from x2_tags\n        ")->queryScalar());
     $admin->disableAutomaticRecordTagging = false;
     $this->assertUpdates($admin, array('disableAutomaticRecordTagging'));
     $this->assertSaves($contact);
     $this->assertEquals(array('#tag0', '#tag1', '#tag2'), Yii::app()->db->createCommand()->select('tag')->from('x2_tags')->order('tag asc')->queryColumn());
 }
开发者ID:dsyman2,项目名称:X2CRM,代码行数:15,代码来源:AdminTest.php

示例2: testModifyColumn

 public function testModifyColumn()
 {
     $schema = Yii::app()->db->schema;
     $field = new Fields('test');
     $field->modelName = $this->getTestModelName();
     $field->fieldName = $this->getTestColumnName();
     $field->type = 'varchar';
     $field->custom = 0;
     $tableName = X2Model::model($field->modelName)->tableName();
     try {
         $field->createColumn();
     } catch (Exception $e) {
         $this->tearDownTestColumn();
         throw $e;
     }
     Yii::app()->db->schema->refresh();
     $columnsAfterAdd = Yii::app()->db->schema->tables[$tableName]->columnNames;
     $column = Yii::app()->db->schema->tables[$tableName]->columns[$field->fieldName];
     $this->assertEquals('varchar(255)', $column->dbType);
     $this->assertTrue(in_array($field->fieldName, $columnsAfterAdd), "Column {$field->fieldName} was not created.");
     // test column modification
     $field->type = 'float';
     $this->assertTrue($field->modifyColumn());
     Yii::app()->db->schema->refresh();
     $column = Yii::app()->db->schema->tables[$tableName]->columns[$field->fieldName];
     $this->assertEquals('float', $column->dbType);
     // test strict mode. Try to truncate column and ensure that modifyColumn returns false in
     // indicating CDbException
     $contact = Contacts::model()->findByPk(12345);
     if (!$contact) {
         // temporary fix to get test to work in opensource. For some reason the contact
         // fixture isn't being loaded.
         $contact = new Contacts();
         $contact->setAttributes(array('id' => 12345, 'name' => 'Testfirstname Testlastname', 'nameId' => 'Testfirstname Testlastname_12345', 'company' => 'Black Mesa_1', 'firstName' => 'Testfirstname', 'lastName' => 'Testlastname', 'email' => 'contact@test.com', 'assignedTo' => 'Anyone', 'visibility' => 1, 'phone' => '(234) 918-2348', 'phone2' => '398-103-6291', 'trackingKey' => '12345678901234567890'), false);
         $contact->save();
     }
     $fieldName = $field->fieldName;
     $field->type = 'text';
     $this->assertTrue($field->modifyColumn());
     Yii::app()->db->schema->refresh();
     $column = $schema->tables[$tableName]->columns[$field->fieldName];
     $this->assertEquals('text', $column->dbType);
     $contact->refreshMetaData();
     // set field value to a string with length > 255
     $contact->{$fieldName} = '111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111';
     $this->assertSaves($contact);
     $field->type = 'varchar';
     Yii::app()->db->createCommand('set sql_mode=STRICT_ALL_TABLES;')->execute();
     $this->assertFalse($field->modifyColumn());
     $column = $schema->tables[$tableName]->columns[$field->fieldName];
     $this->assertEquals('text', $column->dbType);
     Yii::app()->db->createCommand('set sql_mode="";')->execute();
     $this->tearDownTestColumn();
 }
开发者ID:dsyman2,项目名称:X2CRM,代码行数:54,代码来源:FieldsTest.php


注:本文中的Contacts::setAttributes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。