我在我看来有一个自动完成字段,其代码如下
<?php
$data = Members::find()
->select(['first_name as value', 'first_name as label','id as id'])
->asArray()
->all();
echo 'Name' .'<br>';
echo AutoComplete::widget([
'name' => 'member_name',
'clientOptions' => [
'source' => $data,
'minLength'=>'3',
'autoFill'=>true,
'select' => new JsExpression("function( event, ui ) {
$('#receipt-member_id').val(ui.item.id);//#receipt-member_id is the id of hiddenInput.
}")],
]);
?>
Run Code Online (Sandbox Code Playgroud)
自动完成工作正常,它显示所有“成员”的名字。但是可能有很多名字相似的人,所以我想要的是连接 first_name 和 last_name。在正常的下拉菜单中,可以按如下方式完成
<?php
$models1 = Members::find()->all();
$data = array();
foreach ($models1 as $model1)
$data[$model1->id] = $model1->first_name . ' '. $model1->last_name;
echo $form->field($model, 'member_id')->dropDownList(
$data,
['prompt'=>'Select...']);
?>
Run Code Online (Sandbox Code Playgroud)
如何使用自动完成小部件执行此操作?
我怎样才能得到第一行的结果?下面是我的代码,它给了我这样的错误Undefined index: module
if ( substr( $action, 0, 4 ) === "stl_" )
{
$query = "SELECT * FROM a_actions LEFT JOIN a_modules ON ( a_modules.id=a_actions.module_id )
WHERE a_actions.id=(SELECT dependency FROM a_actions WHERE action='{$action}') AND a_modules.module_status = 1 ";
$action = \Yii::$app->db->createCommand( $query )
->queryAll();
//print_r($action);die();
$module = $action[ 'module' ];
$action = $action[ 'action' ];
}
Run Code Online (Sandbox Code Playgroud)
$action 有价值
Array ( [0] => Array ( [id] => 7 [module_id] => 7 [action] => index [label] => Members [dependency] => …Run Code Online (Sandbox Code Playgroud) 我在 ActiveForm 中遇到了 checkboxList 的虚拟问题。
所以我有两个模型(我剪掉了不相关的代码):
对象模型:
class Object extends ActiveRecord
{
public $oFacilities = array();
public static function tableName()
{
return 'objects';
}
public function getObjectFacilities(){
return $this->hasMany(Facility::className(),['id' => 'facilityId'])->viaTable('objectsfacilities', ['objectId' => 'id']);
}
}
Run Code Online (Sandbox Code Playgroud)
设施型号:
class Facility extends ActiveRecord
{
public static function tableName()
{
return 'facilities';
}
public static function forWidget(){
$facilities =static::find()->select(['id','name'])->where(['type' => static::TYPE_OBJECT])
->orderBy('name')
->asArray()
->all();
return ArrayHelper::map($facilities, 'id', 'name');
}
public function getObjectsWithFacility(){
return $this->hasMany(Object::className(), ['id' => 'objectId'])->viaTable('objectsfacilities', ['facilityId' => 'id']);
}
}
Run Code Online (Sandbox Code Playgroud)
我的 …
我正在尝试在 yii2 高级应用程序中更改密码,但总是失败
我有一个模型,它可以找到输入的密码并对照存储的密码进行检查,如果为真,则返回真,但如果为假,则应失败。
这是模型部分
这就是设置用户密码的原因
public function setPassword($password)
{
$this->password = Yii::$app->security->generatePasswordHash($password);
}
Run Code Online (Sandbox Code Playgroud)
这是用于比较两个密码的内容
public function findPasswords($attribute, $params){
$user = UserIdentity::find()->where([
'username'=>Yii::$app->user->identity->username
])->one();
$password = $user->password_hash; //returns current password as stored in the dbase
$hash2 = Yii::$app->security->generatePasswordHash($this->oldpass); //generates an encrypted password
if($password!= $hash2)
{
$this->addError($attribute, 'Old password is incorrect');
}
}
Run Code Online (Sandbox Code Playgroud)
这总是返回旧密码不正确。我也试过
var_dump(Yii::$app->security->generatePasswordHash(5378));
var_dump(Yii::$app->security->generatePasswordHash(5378));
Run Code Online (Sandbox Code Playgroud)
上面的两个返回两个不同的值,这是为什么?
可能有什么问题??
这是更新后的完整用户模型我现在收到获取未知属性的错误:app\models\UserPass::password_hash
class UserPass extends Model{
public $oldpass;
public $newpass;
public $repeatnewpass;
public function rules(){
return [
[['oldpass','newpass','repeatnewpass'],'required'],
['oldpass','findPasswords'],
['repeatnewpass','compare','compareAttribute'=>'newpass'],
];
}
public function …Run Code Online (Sandbox Code Playgroud) 如果用户在 yii2 中处于非活动状态超过 5 分钟,我可以知道如何具有自动注销功能吗?
如何像这样改变单元格的颜色
if($data['type'] == 'London' or $data['type'] == 'Manchester' and $data['from_sale']){
return ['style' => 'background-color:#BCC6F0;'];
}
Run Code Online (Sandbox Code Playgroud)
如果“type”行中的值为 London 或 Manchester,则更改“from_sell”行中单元格的颜色。颜色必须仅在“from_sell”行中的两个单元格中更改
can anyone please tell me why im getting this error ? (the parameter is set i can get it value by echo)
Too few arguments to function app\controllers\admin\SiteDeveloperController::actionView(), 0 passed and exactly 1 expected
Run Code Online (Sandbox Code Playgroud)
+info i passed user identity to view file by mycontroller indexaction so i can access the user id in view with $user->id ;
public function actionIndex()
{
$this->layout = "site-developer";
if (Yii::$app->user->can('superuser')) {
if (!Yii::$app->user->isGuest) {
$user = Yii::$app->user->identity;
return $this->render("index", [
'user' => $user
]); …Run Code Online (Sandbox Code Playgroud) 我正在使用 yii2 实现一个宁静的 api,我想知道如何使用户的访问令牌过期
在我的登录控制器中
if($model->login()){
return [
"access_token' => Yii::$app->user->identity->getAuthKey(),
];
}
Run Code Online (Sandbox Code Playgroud)
现在在我的其他控制器中正在实现这种行为
class DefaultController extends Controller {
$behaviors['authenticator'] = [
'class' => CompositeAuth::className(),
'authMethods' => [
QueryParamAuth::className(),
],
];
}
Run Code Online (Sandbox Code Playgroud)
每当 iu 在我的 url 中使用访问令牌发送我的请求时,它都会起作用
但现在的问题是访问令牌不会过期
如何设置访问令牌的到期时间?
我想更新我的table/model. 场景是,我有一个“状态”列,我想SET将此列设置为一个值,然后根据id. 我想做类似update声明的事情。
Update 'table' SET status = 'status value' where id = 'myid'
我的action controller样子
$model = $this->findModel($id);
$ogp_id = $model->id;
$status = $model->status;
Run Code Online (Sandbox Code Playgroud)
我已经搜索过了,但找不到解决方案
任何帮助将不胜感激
我必须从现有的表数据中创建大量数据。每天大约有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 分钟。