I am trying to send a data from the model but in view page datas are not coming its showing error (Setting unknown property: yiidataActiveDataProvider::WmProducts). Unknown Property – yiibaseUnknownPropertyException
This is my code:-
Controller:-
<?php
namespace frontendcontrollers;
use yiiwebController;
use yiidataPagination;
use frontendmodelsWmProducts;
use yiidataActiveDataProvider;
class ProductsController extends yiiwebController
{
public function actionIndex()
{
return $this->render('index');
}
public function actionView()
{
// $WmProducts = WmProducts::find()->all(); // Calling Model
$WmProducts = WmProducts::find()->select('id,name,is_retail,is_wholesale')->all();
// echo "<pre>";print_r($WmProducts);
// exit;
$dataProvider = new ActiveDataProvider ([
'WmProducts' =>$WmProducts,
'pagination' => false,
]);
// echo "ABC";
// exit;
return $this->render('view', ['dataProvider' =>$dataProvider]);
// return $this->render('view', ['dataProvider' =>$WmProducts]);
}
}
Model:-
<?php
namespace frontendmodels;
use Yii;
use yiibaseModel;
use yiidbActiveRecord;
use yiidataActiveDataProvider;
/**
* This is the model class for table "{{%wm_products}}".
*
* @property int $id
* @property int $manufacturer_id
* @property string $sku
* @property string $manufacturer_sku
* @property string $cola
* @property string $bidcola
* @property string $name
* @property string $slug
* @property float $price
* @property float $price_suggested
* @property float $direct_import_price
* @property float $di_price
* @property float $wholesale_price
* @property float $wholesale_price_suggested
* @property float $distributor_price
* @property float $distributor_price_suggested
* @property int $on_hand
* @property int $default_retail_warehouse_id
* @property int $default_wholesale_warehouse_id
* @property int $default_tax_code_id
* @property float $weight
* @property int $is_bundle
* @property int $items_per_unit
* @property int $items_per_case
* @property string $date_available
* @property int $is_new
* @property string $date_created
* @property string $mod_dt
* @property string $edit_status
* @property string $inventory_status
* @property int $product_type_id
* @property int $is_retail
* @property int $is_wholesale
* @property int $is_distributor
* @property int $sales_target_overwrite
* @property int $special_sales_percentage
* @property int $excluded_from_sales_volume
* @property int|null $is_archived
* @property string $shopify_product_id
*/
class WmProducts extends yiidbActiveRecord
{
public $WmProducts;
public $dataProvider;
public static function tableName()
{
return '{{%wm_products}}';
}
public function rules()
{
return [['id', 'name', 'di_price', 'is_retail', 'is_wholesale']];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'manufacturer_id' => 'Manufacturer ID',
'sku' => 'Sku',
'manufacturer_sku' => 'Manufacturer Sku',
'cola' => 'Cola',
'bidcola' => 'Bidcola',
'name' => 'Name',
'slug' => 'Slug',
'price' => 'Price',
'price_suggested' => 'Price Suggested',
'direct_import_price' => 'Direct Import Price',
'di_price' => 'Di Price',
'wholesale_price' => 'Wholesale Price',
'wholesale_price_suggested' => 'Wholesale Price Suggested',
'distributor_price' => 'Distributor Price',
'distributor_price_suggested' => 'Distributor Price Suggested',
'on_hand' => 'On Hand',
'default_retail_warehouse_id' => 'Default Retail Warehouse ID',
'default_wholesale_warehouse_id' => 'Default Wholesale Warehouse ID',
'default_tax_code_id' => 'Default Tax Code ID',
'weight' => 'Weight',
'is_bundle' => 'Is Bundle',
'items_per_unit' => 'Items Per Unit',
'items_per_case' => 'Items Per Case',
'date_available' => 'Date Available',
'is_new' => 'Is New',
'date_created' => 'Date Created',
'mod_dt' => 'Mod Dt',
'edit_status' => 'Edit Status',
'inventory_status' => 'Inventory Status',
'product_type_id' => 'Product Type ID',
'is_retail' => 'Is Retail',
'is_wholesale' => 'Is Wholesale',
'is_distributor' => 'Is Distributor',
'sales_target_overwrite' => 'Sales Target Overwrite',
'special_sales_percentage' => 'Special Sales Percentage',
'excluded_from_sales_volume' => 'Excluded From Sales Volume',
'is_archived' => 'Is Archived',
'shopify_product_id' => 'Shopify Product ID',
];
}
}
View:-
<?php
use yiigridGridView;
use yiidataActiveDataProvider;
use yiiwidgetsActiveForm;
use yiihelpersHtml;
$dataProvider = new ActiveDataProvider([
'query' => Post::find(),
'pagination' => [
'pageSize' => 20,
],
]);
// get the posts in the current page
// $dataProvider = $dataProvider->getModels();
echo GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
'id',
[
'attribute' => 'name',
'format' => 'text'
],
[
'attribute' => 'wholesale_price',
'format' => 'text'
],
[
'attribute' => 'is_retail',
'format' => 'text'
],
[
'attribute' => 'distributor_price',
'format' => 'Text'
]
]
]);
?>
Please let me know what is the issue and how to solve.