Hello everyone,
I am new to php and mvc so would really appreciate some help.
I used gii to create a customers mvc (based on my customers table). In my customers table, a group of customers
can be grouped together using the cus_group field.
What I want to do is have a link which will take me from the view detail of a single customer to a list of all customers within their group (the same as if you apply a filter in the GridView).
To do this, I have added this html into the gii generated view
<ul class="nav nav-pills">
<li><a href="../web/index.php?r=customers/family&id=1">Family</a></li>
</ul>
In my CustomersController I have this method,
public function actionFamily($id)
{
$searchModel = new CustomersSearch;
$sql = 'SELECT * FROM customers WHERE cus_group ='.$id;
$customers = Customers::findBySql($sql)->all();
return $this->render('family', [
'dataProvider' => $customers,
'searchModel' => $searchModel,
]);
}
The family.php view is the same code as the gii generated index.php.
The problem I am getting when I click the link is the following
PHP Fatal Error – yii\base\ErrorException
Call to a member function prepare() on a non-object
-
in C:\wamp\www\basic\vendor\yiisoft\yii2\widgets\BaseListView.php at line 104
public function init()
{
if ($this->dataProvider === null) { throw new InvalidConfigException('The "dataProvider" property must be set.'); } if ($this->emptyText === null) { $this->emptyText = Yii::t('yii', 'No results found.'); } $this->dataProvider->prepare();
What am I doing wrong?
I am very new to this, if there is tutorial anyone can point me would be really great.
regards
Kashim