我为Yii2使用https://github.com/creocoder/yii2-nested-sets扩展!
所以,Yii1的第一个版本很好,但在这个版本中我有一些问题.
一切都严格按手册完成!
创建所有模型时,我获得错误:
在类别表的任何查询中都会出现此错误.如果删除整个行为的行为;(
分类型号:
<?php
namespace backend\models;
use creocoder\nestedsets\NestedSetsBehavior;
use yii\db\ActiveRecord;
class Categories extends ActiveRecord
{
public function behaviors() {
return [
'tree' => [
'class' => NestedSetsBehavior::className(),
'treeAttribute' => 'tree',
],
];
}
public function transactions()
{
return [
self::SCENARIO_DEFAULT => self::OP_ALL,
];
}
public static function find()
{
return new CategoryQuery(get_called_class());
}
}
Run Code Online (Sandbox Code Playgroud)
CategoryQuery模型:
<?php
namespace backend\models;
use creocoder\nestedsets\NestedSetsQueryBehavior;
use yii\db\ActiveRecord;
class CategoryQuery extends ActiveRecord
{
public function behaviors() { …Run Code Online (Sandbox Code Playgroud) 我尝试整天解决问题:当我尝试在空目录中拉或克隆存在的存储库时,我收到错误:
$ git clone https://bitbucket.org/path_to_repo/aroma
Cloning into 'aroma'...
remote: Counting objects: 1335, done.
remote: Compressing objects: 100% (1174/1174), done.
remote: Total 1335 (delta 618), rReecused 551 (deltea 72)
Receiving objects: 100% (1335/1335), 43.16 MiB | 3.78 MiB/s, done.
Resolving deltas: 100% (618/618), done.
fatal: fsync error on 'H:/Project/testrep/aroma/.git/objects/pack/tmp_pack_xqHCKb': Bad file descriptor
fatal: index-pack failed
Run Code Online (Sandbox Code Playgroud)
我尝试在config中设置pack.windowMemory大小和pack.packSizeLimit等等.同样的错误; [在我能够克隆存储库之前.但出了点问题
我需要帮助!
我有一个工作机制登录DB,但有时我需要登录过程没有DB(假用户使用).
用户模型中的静态方法
public static function findByRoot()
{
$arr = [
'id' => 100,
'created_at' => 1444322024,
'updated_at' => 1444322024,
'username' => 'vasya',
'auth_key' => 'aagsdghfgukfyrtweri',
'password_hash' => 'aa2gsdg123hfgukfyrtweri',
'email' => 'some@email',
'status' => 10,
];
return new static($arr);
}
Run Code Online (Sandbox Code Playgroud)
我也尝试过替代variat方法:
public static function findByRoot()
{
$model = new User();
$model->id = '1000';
$model->username = 'vasya';
$model->status = 10;
return $model;
}
Run Code Online (Sandbox Code Playgroud)
Yii::$app->getUser()->login()需要UserIdentity的工具
做认证:
\Yii::$app->getUser()->login(User::findByRoot());
Run Code Online (Sandbox Code Playgroud)
如果我在login方法中输入db的实名,那就返回了TRUE,那没关系
但是如果放User::findByRoot()(同一个对象)它也会返回 …
谁能告诉我,我有几个模式:一种产品有很多→ 属性,在属性有许多→ 特点 ,我可以这样做:
return Item::find()->where(['code' => $code])->with('properties')->asArray()->one();
Run Code Online (Sandbox Code Playgroud)
结果:
{
title: "????? ???????? ????????? 150 ? ???????",
new: "0",
hit: "0",
recommend: "0",
properties: [
{
//lallala
},
{
//lallala
},
]
}
Run Code Online (Sandbox Code Playgroud)
但我想在每个属性中嵌套行(特征)我怎么能做那么优雅的方式?