problem with joinwith

Hi everyone,

i have to table in my database categories(id,name) and products(id,price,name,category_id) and i made a join query in CategoriesController :

public function actionCommand()

{

    $categories = Categories::find()->joinWith('products')->all();


    return $this->render('command', ['categories'=>$categories]);

}

and i display them in the categories\command view :

foreach ($categories as $category){

    echo $category->name;


  }

now i want to display all the products for a specific category and i dont’t know how.

Please help me if anyone can




foreach ($categories as $category){

    echo $category->name;

    foreach ($category->products as $product) {

        echo $product->name;

    }

}



Please look at the guide:

http://www.yiiframework.com/doc-2.0/guide-db-active-record.html#relational-data