我通过 yii2 create 命令传递原始 sql,但我总是得到一个错误,属性必须是实现 QueryInterface 的类的实例,例如 yii\db\Query 或其子类
这是代码
$sql ="
SELECT
tblpritems.PRlineID
, tblpritems.Tracking_Code
, tblpritems.Description
, tblpritems.Quantity
, tblpritems.Unit_Price
, tblpritems.Extended_price
, tblpritems.PRID
, tblpritems.pr_solicitation_id
, tblpritems.date_item_received
, tblpritems.Quantity_received
, tblpritems.Remarks_on_receipt
, tblpritems.Received_by
FROM
prts.tblpritems
INNER JOIN prts.tblpr
ON (tblpritems.PRID = tblpr.PRID)
INNER JOIN prts.tblprsolicitations
ON (tblprsolicitations.PRID = tblpr.PRID) AND (tblpritems.pr_solicitation_id = tblprsolicitations.pr_solicitation_id)
INNER JOIN prts.tblprsuppliers
ON (tblprsuppliers.pr_solicitation_id = tblprsolicitations.pr_solicitation_id)
INNER JOIN prts.tblpo
ON (tblpo.pr_supplier_id = tblprsuppliers.pr_supplier_id)
where tblpr.PRID=".$val." and tblpo.PO_Status_ID=7 and item_received_status=0
";
$connection = Yii::$app->getDb(); …Run Code Online (Sandbox Code Playgroud) 我想设置验证密码字段包含:
大写字母,小写字母,数字和特殊字符
这是我到目前为止:
passwordValueValidator(control) {
if (control.value != undefined) {
if (!control.value.match(/^(?=.*[0-9])[a-zA-Z0-9!@#$%^&*]{6,100}$/)) {
return { 'invalidPassword': true };
}
else{
//here i need to add check for special characters
}
}
}
Run Code Online (Sandbox Code Playgroud)
以上代码仅适用于字母和数字组合.我还需要添加什么来检查用户是否输入了特殊字符
特殊字符是:( !@#$%^&*()_+按shift +数字0-10输入)
我使用节点js和socket io.我想知道用户连接时使用的浏览器.
通过使用
sockets.on('connection', function(socket) {
var ip_address = socket.conn..remoteAddress; //this fetches the ip address
var userbrowser = socket.conn. //am stuck here
});
Run Code Online (Sandbox Code Playgroud)
我如何获取用户在套接字中使用的类型o浏览器
我已经检查过,console.log(socket.conn) 但我看不到任何有用的浏览器密钥
我试图将类型为string的数据传递给构造,以确保始终传递字符串
在我的重置密码类中,我有
class RequestResetPassword extends Mailable
{
public function __construct(User $user, String $resettoken)
{
}
Run Code Online (Sandbox Code Playgroud)
用户部分是可以的,因为它是用户模型类型,但我如何通过声明它必须始终是一个字符串来访问访问令牌部分
以上产生错误
App string not found.
Run Code Online (Sandbox Code Playgroud) 我试图保护子路线免受父路线的影响,但这失败了
export default new Router({
routes: [
//frontend routes
{
{path: 'auth', component: Auth, children: authroutes,
beforeEnter: (to, from, next) => {
// check if user is a guest or loggedin
auth.canAccess(permissions.is_guest)
.then((res) => {
if (res.data.status) {
next();
} else {
router.push('/auth/not-allowed');
}
})
}}
]
}
]
})
Run Code Online (Sandbox Code Playgroud)
现在在我的孩子路线上
authroutes.js
const authroutes = [
{path: '', redirect: 'login'},
{path: 'login', component: Login, name: "login" },
];
Run Code Online (Sandbox Code Playgroud)
但是,当我将上面的 beforeenter 放在子路由上时,它可以工作,但会导致大量代码重复。
我如何保护孩子免受父母路线的影响
例如:守卫/auth/login 和/auth/register
我的Angular组件中有以下内容:
class Test implements ....{
duration:{from:number, to:number}
constructor(){
this.duration.from = "ddd";//set after some calculations
this.duration.to = "ddd";
}
}
Run Code Online (Sandbox Code Playgroud)
以上返回"无法设置from未定义属性"的错误.
我哪里错了?
我正在雄辩地使用laravel,试图获取包含在不同表中的信息并进行比较。
我的桌子是
tbl_checks
id,check_id, person_id //person_id is the foreign key
tbl_persons
id, category,
Run Code Online (Sandbox Code Playgroud)
我想获取表中的所有人员,tbl_checks然后按人员类别对数据进行分组tbl_persons.category。
在普通的SQL语句中,它类似于:
select from tbl_checks group by tbl_person.category where the tbl_persons.id is contained in tbl_checks.person_id
Run Code Online (Sandbox Code Playgroud)
在我的模型中,我有:
class PersonsModel extends Model {
//connect to the next database
protected $connection = 'inspection';
protected $table = 'tbl_trucks';
//relation with tbl_checks
public function checks(){
return $this->hasMany('App\TblChecks','person_id','id');
}
}
Run Code Online (Sandbox Code Playgroud)
如何使用ELoquent模型,而不是Db门面?为了使它清晰。我试图找到所有在table_checks中的人,而忽略不在tbl_checks中的人id
我正在尝试在 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 实现一个宁静的 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 中使用访问令牌发送我的请求时,它都会起作用
但现在的问题是访问令牌不会过期
如何设置访问令牌的到期时间?
如果路线匹配某种模式,我想分配课程.
假设我有以下这些urls:
user-management/users
user-management/roles
user-management/role?user=andy
user-management/permissions
Run Code Online (Sandbox Code Playgroud)
现在我想在链接中添加活动类.所以我尝试过:
<li class="{{ (Request::path() == 'user-management/*') ? 'dropdown active ' : 'dropdown' }}">
Run Code Online (Sandbox Code Playgroud)
但是上面没有添加活动类.尝试:
<li class="{{ (Request::path() == 'user-management/users') ? 'dropdown active ' : 'dropdown' }}">
Run Code Online (Sandbox Code Playgroud)
我访问时哪个有效 /user-management/users
如何使另一个与所有user-management链接一起工作urls
还有什么可能是错的?
现在用laravel 5.5和我的路线web.php是
Route::group(["middleware"=>'auth', 'prefix'=>'user-management'], function (){
Route::get("users", "UsersController@ShowUsers")->name("user-management.users");
Route::get("roles", "UsersController@ShowRoles")->name("user-management.roles");
.....others follow
Run Code Online (Sandbox Code Playgroud)
});
我正在尝试获取前一天午夜的时间戳
也就是说,如果今天是星期四,请获取星期三午夜的时间戳。
我该怎么办
我试过了
$lastdaymidnight = strtotime() //am stuck
Run Code Online (Sandbox Code Playgroud)
我需要在strtotime中添加什么?
我已经通过npm安装了vue轮播
"dependencies": {
"nuxt": "^1.0.0",
"vue-carousel": "^0.6.9"
},
Run Code Online (Sandbox Code Playgroud)
现在在我的nuxt配置中
plugins: [
'~/plugins/vue-carousel'
],
Run Code Online (Sandbox Code Playgroud)
还有vue-carousel.js
import Vue from 'vue';
import VueCarousel from 'vue-carousel';
Vue.use(VueCarousel);
Run Code Online (Sandbox Code Playgroud)
现在在我的组件中将其用作
<template>
<div>
<carousel>
<slide>
Slide 1 Content
</slide>
<slide>
Slide 2 Content
</slide>
</carousel>
</div>
</template>
<script>
import Carousel from 'vue-carousel';
import Slide from 'vue-carousel';
export default {
components:{
Carousel,Slide
}
}
Run Code Online (Sandbox Code Playgroud)
我在哪里出错并收到错误
render function or template not defined in component: carousel
Run Code Online (Sandbox Code Playgroud) 我有以下数组
let registrations = [
{user:1, reg_on:'12/02/2009'},
{user:10, reg_on:'11/02/2009'},
{user:5, reg_on:'11/02/2109'},
///others
]
Run Code Online (Sandbox Code Playgroud)
因此,现在尝试查找一个用户为1或5的记录,即第一个
所以我做了以下工作
let final = registrations.find(reg=>reg.user === 1 ||reg.user === 5);
Run Code Online (Sandbox Code Playgroud)
上面的方法有效,但是如果需要添加更多的过滤器参数(如reg.user === 10),则变得很乏味。
所以我试图像这样重构
let final = registrations.find(reg=>reg.user.includes([1,5,10]));
Run Code Online (Sandbox Code Playgroud)
但是现在,包含一个的行不通了。我错过了什么?