oldnew
- oldnew 回复了话题 YII2 rules规则里面的参数要怎么取
错误信息看了没
- oldnew 2018-04-18 已签到连续签到4天,获得了20个金钱
- oldnew 2018-04-17 已签到连续签到3天,获得了15个金钱
还有一些其它字段的设置,意思看字面就知道了就不用打出来了吧,罗列如下:
notNull() null() unique() check($check) defaultValue($default) comment($comment) unsigned() after($after) first() defaultExpression($default) append($sql)
哦对了,如果设置了unsigned():
'id' => $this->primaryKey()->unsigned(),
对应的处理也会改变,比如myql的处理会变为:
'int(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY'
另外在使用bigPrimaryKey()时,有无unsigned()的处理分别是(以mysql为例):
'bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY', 'bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY',
根据代码:
public function primaryKey($length = null) { return $this->getDb()->getSchema()->createColumnSchemaBuilder(Schema::TYPE_PK, $length); }
可知在primaryKey()中传递的是TYPE_PK,是不是auto_increment看看yii2对TYPE_PK的处理就知道了:
mysql:
'int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY'
mssql:
'int IDENTITY PRIMARY KEY',
oci:
'NUMBER(10) NOT NULL PRIMARY KEY',
pgsql:
'serial NOT NULL PRIMARY KEY',
sqlite:
'integer PRIMARY KEY AUTOINCREMENT NOT NULL',
public function primaryKey($length = null) public function bigPrimaryKey($length = null) public function char($length = null) public function string($length = null) public function text() public function tinyInteger($length = null) public function smallInteger($length = null) public function integer($length = null) public function bigInteger($length = null) public function float($precision = null) public function double($precision = null) public function decimal($precision = null, $scale = null) public function dateTime($precision = null) public function timestamp($precision = null) public function time($precision = null) public function date() public function binary($length = null) public function boolean() public function money($precision = null, $scale = null) public function json()
就是上面这些,拿去用吧
- oldnew 2018-04-16 已签到连续签到2天,获得了10个金钱
session写到数据库了?
如果是用户的个人信息,可以用
Yii::$app->user->identity->username;
其它的话,可以通过
params
这个属性://View 文件源码 class View extends Component implements DynamicContentAwareInterface { ... /** * @var mixed custom parameters that are shared among view templates. */ public $params = []; ... }
用法举例
首先需要在视图文件中:
$this->params['model'] = $model; $this->params['example'] = $example; ...
然后在
main.php
布局文件中就可以:$model = $this->params['model']; $example = $this->params['example']; ... print_r($model); //在你需要显示的地方显示 print_r($example); //在你需要显示的地方显示
@dada 视图中怎么取,在布局文件header和footer中也还是那样取,一样一样的