我在 Yii2 中编写了一个应用程序,不幸的是,我们丢失了所有数据库备份。我们现在拥有的只是应用程序文件。是否有更短的方法根据现有模型重新创建 98 个数据库表?我注意到大约 22 个表的架构被缓存在“/app/runtime/cache”下。有人做过这样的事吗?
我正在为登录用户搜索用户角色,我没有得到如何打印用户角色名称.我试过这个:
$Role = Yii::$app->authManager->getRolesByUser(Yii::$app->user->getId());
Run Code Online (Sandbox Code Playgroud)
什么时候,我做了print_r($Role); 我懂了 :
Array ( [superadmin] => yii\rbac\Role Object ( [type] => 1 [name] => superadmin [description] => Super admin can do any operation in the application [ruleName] => [data] => [createdAt] => [updatedAt] => ) )
Run Code Online (Sandbox Code Playgroud)
我希望获得特定的角色名称,但我无法访问
Array ( [superadmin] => yii\rbac\Role Object ........)
^ unable to access this name.
Run Code Online (Sandbox Code Playgroud)
打字时print_r($Role[0]->name);我得到的错误就像
PHP注意 - yii\base\ErrorException
未定义的偏移量:0
并且,如果我喜欢这种方式(意味着,手动传递$rolename给数组索引)它正在工作.
$roleName = 'superadmin';
print_r($Role[$roleName]->name);
Run Code Online (Sandbox Code Playgroud)
为什么这个要求来找我,因为对于登录用户它是好的.但是,如果我想知道其他用户角色名称,那么我需要在这里传递索引名称$Role[$roleName]->name
请帮我看看'superadmin'.我没有得到如何得到它的索引名称.
Array ( [superadmin] => yii\rbac\Role Object …Run Code Online (Sandbox Code Playgroud) 我BearerAuth在我的 yii2 项目中使用,身份验证在我的本地计算机上工作正常,但是当我在我的服务器上上传相同的代码和数据库时,它不工作并抛出Unauthorised错误。
我试图header在屏幕上打印,我可以看到access_token标题中没有。我正在POSTMAN用于测试,我正在使用以下令牌在标头中传递令牌
有什么我做错了吗?有没有其他方法可以Authrorisation在服务器上发送标头?
那access_token是在数据库中。我也尝试在服务器上调试它,但它没有转到User模型的方法findIdentityByAccessToken并在此之前抛出错误。
就像我想创建名为"dt()"的函数
function dt(){
return date('Y-m-d H:i:s');
}
Run Code Online (Sandbox Code Playgroud)
并希望像这样访问它: -
echo dt(); //retrun current date and time format
Run Code Online (Sandbox Code Playgroud)
在Yii2框架中哪个更好的地方呢?
我是YII的新手,使用yii2 basic。实际上,我想知道如何从同一文件夹的视图中包含另一个视图页面。假设我正在查看home.php。我需要在home.php正文中包含post.php视图页面。我将如何执行呢?
我需要在 Yii2 基本框架中用 2 种语言制作网站,但是,我在谷歌和其他搜索引擎上研究了很多次,我只能找到 yii2 高级内化。我需要基本模式,如果你有 yii2 基本多语言的源代码,或者如果你知道任何关于 yii2 基本内化的链接或视频教程,请与我分享,我会非常感激。
我期待着尽快收到您的来信。
我正在尝试正确提交事件(onsubmit 设置为内联),但它会被触发两次,这不是我们想要的行为。
我的ActiveForm代码:
<?php
use app\models\Countries;
use app\models\States;
use yii\bootstrap\ActiveForm;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
$form = ActiveForm::begin(
[
'action' => 'user-default-shipping/create',
'options' => [
'onsubmit' => 'Address.createDefault(event, this)'
]
]
);
if ($model->id)
echo Html::activeHiddenInput($model, 'id');
echo $form->field($model, 'city')->textInput();
echo $form->field($model, 'address')->textInput();
echo $form->field($model, 'zip')->input('text');
echo $form->field($model, 'country_id')
->dropDownList(ArrayHelper::map(Countries::find()->all(), 'country_id', 'country_name'),
['role' => 'countries']
)->hint('Choose your country.');
echo $form->field($model, 'state_id')
->dropDownList(ArrayHelper::map(States::find()->all(), 'state_id', 'state_name'),
[
'role' => 'states'
]
)->hint('Choose your state.');
?>
<div class="form-group">
<button type="submit" class="btn btn-green">Submit</button> …Run Code Online (Sandbox Code Playgroud) 我有一个"post"表,其中包含属性"user_id",以便知道谁发布了该帖子.我遇到了一个问题,当创建一个帖子时,'user_id'没有添加到数据库中,这不能为null,所以我不能从那里继续.那么如何自动添加当前登录用户的"user_id".
我正在使用Yii2基本模板.
谢谢
我必须从现有的表数据中创建大量数据。每天大约有5000到10000条数据。
我的控制器:
$skus = Sku3d::find()->all();
foreach ($skus as $sku) {
$model = new Loghour3d();
$model->sku = $sku->sku;
$model->modeler = $sku->modeler;
$model->team = $sku->team;
$time = new \DateTime('now');
$today = $time->format('Y-m-d');
$model->day = $today;
$model->handover = $sku->handover;
$model->hour = $sku->totalhours;
$model->save();
}
Run Code Online (Sandbox Code Playgroud)
但是创建的时间不正确。示例:$sku->totalhours = 12但是$model->hour = 600我的代码是$model->hour = $sku->totalhours;. 所以我不知道从哪里来600。
还有没有更好的方法来完成这项任务,因为现在大约需要 15-20 分钟。
我有一个项目,他们有 3 个状态。现在我需要统计每天每种状态的数量和总数。
我可以单独列出它们。但不知道如何将它们结合起来。
这是我的代码:
$passed_counts = (new \yii\db\Query())
->select(['date', 'week', 'count(sku) as sku'])
->from('qa3d')
->where(['status' => 'Passed'])
->groupBy('date')->all();
$failed_counts = (new \yii\db\Query())
->select(['date', 'week', 'count(sku) as sku'])
->from('qa3d')
->where(['status' => 'Failed'])
->groupBy('date')->all();
$onhold_counts = (new \yii\db\Query())
->select(['date', 'week', 'count(sku) as sku'])
->from('qa3d')
->where(['status' => 'On Hold'])
->groupBy('date')->all();
$total_counts = (new \yii\db\Query())
->select(['date', 'week', 'count(sku) as sku'])
->from('qa3d')
->groupBy('date')->all();
Run Code Online (Sandbox Code Playgroud)
现在我可以将它们分别列在 4 个表中。我想像这样将它们组合在一张表中,但不知道如何。
date Passed Failed On Hold Total
2019-01-16 1 4 2 7
2019-01-17 1 0 2 3
请在这件事上给予我帮助。
谢谢。