user2027175
user2027175

Reputation: 83

Simple create an object in Codeigniter

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

Answers (2)

Aurel
Aurel

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

Nil'z
Nil'z

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

Related Questions