I am trying to use ArrayHelper in Yii2 advanced template project and it says Class ArrayHelper not found. I added use yii\helpers\ArrayHelper and it works in controller. But this problem continue to happen when I use ArrayHelper in view file. How can I autoload these classes in Yii2.
-
Please tell us what have you attempted so far. Refer here on how to askPSWai– PSWai2015-12-15 03:56:02 +00:00Commented Dec 15, 2015 at 3:56
-
please explain your question deeply??vishuB– vishuB2015-12-15 04:28:12 +00:00Commented Dec 15, 2015 at 4:28
-
Can you please add your code sample.Chetan Sharma– Chetan Sharma2015-12-15 07:17:22 +00:00Commented Dec 15, 2015 at 7:17
Add a comment
|
2 Answers
You Did not show the code . So i am not able to give you the exact answer: But you ask that you want to use array helper in your view so try this: it is working .
use app\models\User;
use yii\helpers\ArrayHelper;
//use app\models\user;
$user=User::find()->all();
//use yii\helpers\ArrayHelper;
$listData=ArrayHelper::map($user,'user_id','username');
echo '<pre>';
print_r($listData);
echo '</pre>';
for more details visit :Yii2 Docs