Yii2 require all Controller and Action to login

Place this rule in the beginning of the rules section: [ ‘allow’ => true, ‘roles’ => [‘@’], ], Omitting the actions means all actions. So your AccessControl config will be like this: public function behaviors() { return [ ‘access’ => [ ‘class’ => AccessControl::className(), ‘rules’ => [ [ ‘allow’ => true, ‘roles’ => [‘@’], ], … Read more

Get first character of UTF-8 string

$first_char = mb_substr($title, 0, 1); You need to use PHP’s multibyte string functions to properly handle Unicode strings: http://www.php.net/manual/en/ref.mbstring.php http://www.php.net/manual/en/function.mb-substr.php You’ll also need to specify the character encoding in the <head> of your HTML: <meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ /> or: <meta http-equiv=”Content-Type” content=”text/html; charset=UTF-16″ />

Jquery – Uncaught TypeError: Cannot use ‘in’ operator to search for ‘324’ in

You have a JSON string, not an object. Tell jQuery that you expect a JSON response and it will parse it for you. Either use $.getJSON instead of $.get, or pass the dataType argument to $.get: $.get( ‘index.php?r=admin/post/ajax’, {“parentCatId”:parentCatId}, function(data){ $.each(data, function(key, value){ console.log(key + “:” + value) }) }, ‘json’ );

Yii2 subquery in Active Record

Assuming that your models are named BaseTwitter and BaseFollower accordingly, this should work: $subQuery = BaseFollower::find()->select(‘id’); $query = BaseTwitter::find()->where([‘not in’, ‘id’, $subQuery]); $models = $query->all();

Matching all values in IN clause

You can do something like this: select ItemID from ItemCategory where CategoryID in (5,6,7,8) <– de-dupe these before building IN clause group by ItemID having count(distinct CategoryID) = 4 <–this is the count of unique items in IN clause above If you provide your schema and some sample data, I can provide a more relevant … Read more

yii CPasswordHelper: hashPassword and verifyPassword

CPasswordHelper works like PHP’s functions password_hash() and password_verify(), they are wrappers around the crypt() function. When you generate a BCrypt hash, you will get a string of 60 characters, containing the salt. // Hash a new password for storing in the database. $hashToStoreInDb = password_hash($password, PASSWORD_BCRYPT); The variable $hashToStoreInDb will now contain a hash-value like … Read more