passing value from controller to model code igniter

Hello, I have a function in my controller as follows:

function productWetarea()
       {
          $category=$this->uri->segment(3);
          echo $category;
          $this->load->model('modelviewdata');          
          $this->data['p4'] = $this->modelviewdata->$category.item1Info(); // call viewdata model method.
          $this->data['p5'] = $this->modelviewdata->$category.item2Info(); // call viewdata model method.
          $this->data['p6'] = $this->modelviewdata->$category.item3Info(); // call viewdata model method.
          $this->load->view("viewWetarea", $this->data);          
          
          $this->load->view("footer");
   }

Open in new window


In my model I have the following:

function product1Item1Info() 
 			{
   
    $this->db->select('*');
	$this->db->from('table1');	
	$this->db->where('item',"test");
	$query = $this -> db -> get();
    return $query->result();

 			}

 			function product1Item2Info() 
 			{
   
    $this->db->select('*');
	$this->db->from('table');	
	$this->db->where('item',"test2");
	$query = $this -> db -> get();
    return $query->result();

 			}

 			function product1Item3Info() 
 			{
   
    $this->db->select('*');
	$this->db->from('table');	
	$this->db->where('item',"test3");
	$query = $this -> db -> get();
    return $query->result();

 			}

Open in new window


in my model, product1 = $category (from my controller). When I run this controller ../productInfo/productMyarea/product1, I get the following error:

A PHP Error was encountered

Severity: Notice

Message: Undefined property: ProductInfo::$product1

Filename: core/Model.php



Thank you,
A
aej1973Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
Is there a line number associated with the message?

I ask because the code snippets here do not contain ProductInfo::$product1 so we may not be looking at the code that is causing the trouble
aej1973Author Commented:
Ray, product1 is the value segment3 and productInfo is my controller.

Thanks,
A
aej1973Author Commented:
Is this  a correct way of passing a variable between a controller and the model?

controller:

function productList()
       {
          $tbl=$this->uri->segment(3);
          this->load->model('modelviewdata');
          $this->data['p1'] = $this->modelviewdata->prodInfo($tbl); 
          $this->load->view("productArea", $this->data); 
     }

Open in new window


Model:

function prodInfo($tbl) 
 			{
                            $this->db->select('*');	
	                   $this->db->where('type',<wbr ></wbr>"Composite<wbr ></wbr>");
	                   $query = $this -> db -> get($tbl);
                           return $query->result();
 			}

Open in new window


I am getting a "internal Server Error" when I run this. Thanks for the help.

A
Marco GasiFreelancerCommented:
Yes, A, that's the correct way to pass values to a model. But I suspect your error is not related to this: I think it is related to the use of $this->data: In CI you usually have to use just $data:

          
          $data['p1'] = $this->modelviewdata->prodInfo($tbl); 
          $this->load->view("productArea", $data); 

Open in new window


Within the view you'll get your data accessing them this way:

  $mydata = $p1;

Open in new window


If you use $this->data you must before to define it as a property of your controller
private $data

Open in new window

but I don't see any reason to do this when you have the tremendously useful CI $data array to pass values to your views.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
aej1973Author Commented:
Got it, thank you.

A
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.