-
arun67
Newbie
-
Posts: 1
Threads: 1
Joined: Aug 2020
Reputation:
0
hi,
I am trying to generate a page in Codeigniter 3.1.
Following is the code for Controller
Code: public function list_products()
{
$this->load->model('masters/ProductCategoryCat_model', 'pmode');
$this->load->model('masters/FactoryCat_model', 'fmode');
$this->data['title'] = 'View Product Category List';
$this->data['response_msg'] = $this->session->flashdata('response_msg');
$this->data['response_success'] = $this->session->flashdata('response_success');
$this->data['product_category'] = $this->pmode->getProdcuCategoryList();
log_message('error','product_category:' . json_encode($this->data['product_category']));
foreach ($this->data['product_category'] as $item_key => $item) {
var_dump($this->data['product_category']);
$factory_list = $this->fmode->getFactoryByProductId($item->id);
log_message('error','factory_list:' . json_encode($factory_list));
foreach($factory_list as $fact_key=>$factory)
{
var_dump($factory);
$this->data['product_category'][$item_key]['factory'][$fact_key] = $factory->factory_name;
}
}
log_message('error','data:' . json_encode($this->data));
$this->renderTemplate('masters/product_category/product_category_list', $this->data);
}
Whenever I try to run this code it generates following error:
An uncaught Exception was encountered
Type: Error
Message: Cannot use object of type stdClass as array
It seems error is at the following line:
$this->data['product_category'][$item_key]['factory'][$fact_key] = $factory->factory_name;
Values of $this->data['product_category']:
[{"id":"1","category_name":"PVC_BOND","category_description":"PVC SHOES ","status":"Active"},{"id":"2","category_name":"PVC_SLIPPER","category_description":"air blowing slippers ","status":"Active"},{"id":"3","category_name":"GUMBOOT","category_description":"PVC GUMBOOT ","status":"Active"},{"id":"4","category_name":"EVA","category_description":"MEN & WOMEN EVA SLIPPERS ","status":"Active"},{"id":"5","category_name":"PU","category_description":"PU SLIPPERS ","status":"Active"},{"id":"6","category_name":"PVC_BELLY","category_description":"PVC LADIES BELLY ","status":"Active"},{"id":"7","category_name":"GAUTAM MADAAN","category_description":"","status":"Active"},{"id":"8","category_name":"TEST_TR-78.55","category_description":"test category","status":"Active"}]
And Value of $factory_list:
[{"factory_id":"1","factory_name":"RAMANAND ENTERPRISES PLOT NO 13 14"},{"factory_id":"20","factory_name":"TEST58"}]
ERROR - 2020-08-21 16:09:06 --> Severity: error --> Exception: Cannot use object of type stdClass as array C:\Apache24\htdocs\inv\application\controllers\masters\Variety.php 72
What am I doing wrong here.
Can you help me please.
Regards
-
kleber
Member
-
Posts: 52
Threads: 5
Joined: Jan 2018
Reputation:
0
(08-21-2020, 06:48 AM)arun67 Wrote: hi,
I am trying to generate a page in Codeigniter 3.1.
Following is the code for Controller
Code: public function list_products()
{
$this->load->model('masters/ProductCategoryCat_model', 'pmode');
$this->load->model('masters/FactoryCat_model', 'fmode');
$this->data['title'] = 'View Product Category List';
$this->data['response_msg'] = $this->session->flashdata('response_msg');
$this->data['response_success'] = $this->session->flashdata('response_success');
$this->data['product_category'] = $this->pmode->getProdcuCategoryList();
log_message('error','product_category:' . json_encode($this->data['product_category']));
foreach ($this->data['product_category'] as $item_key => $item) {
var_dump($this->data['product_category']);
$factory_list = $this->fmode->getFactoryByProductId($item->id);
log_message('error','factory_list:' . json_encode($factory_list));
foreach($factory_list as $fact_key=>$factory)
{
var_dump($factory);
$this->data['product_category'][$item_key]['factory'][$fact_key] = $factory->factory_name;
}
}
log_message('error','data:' . json_encode($this->data));
$this->renderTemplate('masters/product_category/product_category_list', $this->data);
}
Whenever I try to run this code it generates following error:
An uncaught Exception was encountered
Type: Error
Message: Cannot use object of type stdClass as array
It seems error is at the following line:
$this->data['product_category'][$item_key]['factory'][$fact_key] = $factory->factory_name;
Values of $this->data['product_category']:
[{"id":"1","category_name":"PVC_BOND","category_description":"PVC SHOES ","status":"Active"},{"id":"2","category_name":"PVC_SLIPPER","category_description":"air blowing slippers ","status":"Active"},{"id":"3","category_name":"GUMBOOT","category_description":"PVC GUMBOOT ","status":"Active"},{"id":"4","category_name":"EVA","category_description":"MEN & WOMEN EVA SLIPPERS ","status":"Active"},{"id":"5","category_name":"PU","category_description":"PU SLIPPERS ","status":"Active"},{"id":"6","category_name":"PVC_BELLY","category_description":"PVC LADIES BELLY ","status":"Active"},{"id":"7","category_name":"GAUTAM MADAAN","category_description":"","status":"Active"},{"id":"8","category_name":"TEST_TR-78.55","category_description":"test category","status":"Active"}]
And Value of $factory_list:
[{"factory_id":"1","factory_name":"RAMANAND ENTERPRISES PLOT NO 13 14"},{"factory_id":"20","factory_name":"TEST58"}]
ERROR - 2020-08-21 16:09:06 --> Severity: error --> Exception: Cannot use object of type stdClass as array C:\Apache24\htdocs\inv\application\controllers\masters\Variety.php 72
What am I doing wrong here.
Can you help me please.
Regards
PHP Code: $data = array();
$product_category = json_decode('[{"id":"1","category_name":"PVC_BOND","category_description":"PVC SHOES ","status":"Active"}, {"id":"2","category_name":"PVC_SLIPPER","category_description":"air blowing slippers ","status":"Active"}, {"id":"3","category_name":"GUMBOOT","category_description":"PVC GUMBOOT ","status":"Active"}, {"id":"4","category_name":"EVA","category_description":"MEN & WOMEN EVA SLIPPERS ","status":"Active"}, {"id":"5","category_name":"PU","category_description":"PU SLIPPERS ","status":"Active"}, {"id":"6","category_name":"PVC_BELLY","category_description":"PVC LADIES BELLY ","status":"Active"}, {"id":"7","category_name":"GAUTAM MADAAN","category_description":"","status":"Active"}, {"id":"8","category_name":"TEST_TR-78.55","category_description":"test category","status":"Active"}]');
$factory_list = json_decode('[{"factory_id":"1","factory_name":"RAMANAND ENTERPRISES PLOT NO 13 14"},{"factory_id":"20","factory_name":"TEST58"}]');
foreach ($product_category as $item_key => $item) {
foreach($factory_list as $fact_key=>$factory){
$data['product_category'][$item_key]['factory'][$fact_key] = $factory->factory_name; }
}
print_r($data);
|