**YII** 系列七Database
来源:互联网 发布:windows android忘仙 编辑:程序博客网 时间:2024/06/06 21:30
>使用步骤
>>创建数据库
>>配置数据库连接
>>创建活动记录的模型
>>创建操作
>>创建渲染用的视图
>>运行
>foreach循环是PHP语句,在html语句中的穿插如下:
<span style="font-size:14px;"><?php foreach ($countries as $country): ?> <li> <?= Html::encode("{$country->name} ({$country->code})") ?>: <?= $country->population ?> </li><?php endforeach; ?></span>//巧妙地解决了php中输出html语句需要使用html组成的字符串的问题
>&model= new user();与$query=User::find()生成的结果是不同的
前者是得到一个对象,可以通过调用属性和方法,进行操作;前者的道德是Activerecord
后者形成的是一个对象数组,本质是数组,可以调用数组的相关方法。后者得到的是Activequery
>数据库对象的使用activeForm
作用:it is the base class for classex representing relational data in terms of objects;
>>返回数据库和表的一些性质
activeAttributes()返回性质的名称在当前场景中
attributes() return the list of all attribute names of the model;
equals($record) returns a value indicatino whether the fiven active record is the same as the current one
primaryKey()返回主键名称,放在数组中
tabelName()返回表格的名称declares the name of the database table associated withe this AR class
>>delete系列
delete() the table row corresponding to this active record; attention:veforeDelete();afertDelete()
deleteall($condition='',$params=[]) delete rows in the table usein the provided conditions,参数使用where中的参数
deleteInternal() deletes an ActiveRecord without considering transction.
>>find系列:
find() creates an activequery instance fro query prupose.能够调用yii\db\activequery和yii\db\active\queryinterface中的方法,进行限定
findByCondition($condition,$one) finds ActiveRecord instances by the geiven condition.
findAll() returns a list of active record models that match the specified primary key values or a set of column valust;参数可以是a scalar value/an array scalar values/an array of name-value pairs.
findOne()returns a single(the first to be queryed) active record model instance by a primary key or an array of column values
findBySql($aql,$params=[ ])使用sql语句进行查询,其中$sql是sql字符串
>>get系列
getDb returns the database connerction used by thiis AR class.
getTableSchema() returns the schema infrormation of the DV tavle associated with AR class
>>insert系列
insert($runValidation= true,$attributes =null) inserts a row into the associated database table usering the attribute values of this record.
insertInternal() inserts an Active Recored into DB without considering transaction.
updata系列
>get到一个新的覆盖原函数的方法
<span style="font-size:14px;">class Customer extends ActiveRecord{ public static function find() { return parent::find()->where(['deleted' => false]); }}// Use andWhere()/orWhere() to apply the default condition// SELECT FROM customer WHERE `deleted`=:deleted AND age>30$customers = Customer::find()->andWhere('age>30')->all();// Use where() to ignore the default condition// SELECT FROM customer WHERE age>30$customers = Customer::find()->where('age>30')->all();</span>//使用parent调用覆盖之前的函数,有点意思
>yii\helpers\html(补充上一节中类的常用属性)
>类使用的进度表
>>yii\web\controller
>>yii\db\baseActiveRecord
>>yii\db\ActiveRecord
>>yii\db\activeQuery
>>yii\data\pagination
>>yii\widgets\LinkPager
>>yii\web\controller
- **YII** 系列七Database
- redis学习系列(七)--redis-database
- **YII** 系列一理论知识
- **YII** 系列六Froms
- 【Yii系列】处理请求
- Yii 2.0 User Login From Database
- Yii学习系列之yii大致结构
- **YII** 系列二yii的基本理解
- **YII**系列三建立表单
- **YII** 系列四数据库访问
- **YII** 系列八应用结构
- Yii 使用七牛上传图片
- yii-besic (七)model 的使用
- php yii2提示Database Exception – yii\db\Exception错误
- YII 框架:php框架系列之新秀YII
- **YII** 系列五yii框架的总体理解
- Datawindow.net 系列七
- svm系列七
- javaScript笔记(四) 数组 和 函数
- Hadoop2.7集群安装
- RabbitMQ Java 实例
- mysql 下locate和find_in_set的使用
- Cannot resolve corresponding JNI function
- **YII** 系列七Database
- Html JS 小技巧
- ViewPager在首尾页滑动切换
- C语言快速查找与二分查找0804
- jQuery自定义表单验证
- vim编码方式的设置
- ./rabbitmq-server:行63: erl: 未找到命令
- ubuntu下 Gedit 中文乱码(命令行模式简单)
- 百度地图API获取发布版SHA1