Reputation: 83
I have two function one is get data from DB:
$data['article']=$this->Marticle->get_article_where($id);
and after an data path to view. Part of data are data for title and description tags.
In another function I would like send tag and description to the same view manually. For this I created an object:
$this->article = new stdClass();
$data['article'][0]->title='how to create an object in Ci';
$data['article'][0]->description='This article will help with creating...:)';
and then I get error "Message: Creating default object from empty value" I know that is just notice and how I can disable it. Also I read related topic, however there was suggestion to create Class. Is simple way to resolve this task ?
Upvotes: 0
Views: 81
Reputation: 3740
if you do not want this error try this :
$data['article'] = array();
$data['article'][0] = new stdClass();
$data['article'][0]->title='how to create an object in Ci';
$data['article'][0]->description='This article will help with creating...:)';
$data['article'][1] = new stdClass();
//$data['article'][1]->title = ...
But i did not understand why $this->article
?
Upvotes: 1
Reputation: 7475
Try this may help:
$data['article']=$this->Marticle->get_article_where($id)->result();
echo "<pre>";print_r( $data['article'] );die;
The ->result()
will return the object and ->result_array()
will return array.
Upvotes: 0