3

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.

3
  • Please tell us what have you attempted so far. Refer here on how to ask Commented Dec 15, 2015 at 3:56
  • please explain your question deeply?? Commented Dec 15, 2015 at 4:28
  • Can you please add your code sample. Commented Dec 15, 2015 at 7:17

2 Answers 2

11

make sure you add namespace in view file too.

//in view_file_name.php
use yii\helpers\ArrayHelper;
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.