Work with result in controller |
[eluser]MaxEisley[/eluser]
Hello guys, i really still cannot find how to work with results in Controller. I can work with results only in viewer. This is my data model, this function check, if the customer with these parameters exists: Code: function checkcustomer($phone, $email, $name, $surname) { This is my controller getting valid entries from viewer. I want to check, if customer with these values exists and when yes, then get customer_ID, when doesn't exist, then create customer: Code: $data['customer'] = $this->data_model->checkcustomer($this->input->post('Phone'), $this->input->post('Email'), $this->input->post('FirstN'), $this->input->post('SecondN')); And it writes these errors, i dont know how to work with results from Model in Controller: Message: Undefined variable: customer Message: Trying to get property of non-object
[eluser]CroNiX[/eluser]
Well, in your controller you store it in $data['customer'] but you are trying to check in $customer. It shows up as $customer only in your view and as $data['customer'] in your controller. So, in your controller, if you did: Code: $customer = $this->data_model->checkcustomer($this->input->post('Phone'), $this->input->post('Email'), $this->input->post('FirstN'), $this->input->post('SecondN')); Code: if($customer->zakaznikID == '') Code: if($data['customer']->zakaznikID == '')
[eluser]MaxEisley[/eluser]
It doesnt work: Code: $customer = $this->data_model->checkcustomer($this->input->post('Phone'), $this->input->post('Email'), $this->input->post('FirstN'), $this->input->post('SecondN')); It still writes Trying to get property of non-object on line: if($customer->zakaznikID == '') {
[eluser]CroNiX[/eluser]
well, in your query, are you returning the results as an array or object? It would appear an array and you are trying to access it as an object. Do a var_dump($customer) and see what the data looks like.
[eluser]MaxEisley[/eluser]
I am receiving data from this: Code: function checkcustomer($phone, $email, $name, $surname) {
[eluser]skiter[/eluser]
You have a ROW, so is not an Object, this mean that you have array in array, in array? Anyway $row[0] is ur's 1 element from 'Select * ...', if you add (row results), to array, you will have multi-dimension array, then access liek others multi-dimension arrays. Code: if($data['customer']['ID'] == '') { To many arrays in one post, sorry my en is quite poor
[eluser]MaxEisley[/eluser]
So what i should change in data_model to result it not as an array ?
[eluser]TWP Marketing[/eluser]
The User Guide ( http://ellislab.com/codeigniter/user-gui...esults.htm ) says that your returned value should be an OBJECT: Quote:... Does your customer file "zakaznik" contain the field zakaznikID? Second thought, if the query finds NO record it will return FALSE, which could give you the error "Trying to get property of non-object". You should add the code to test if rows were found (in the User Guide example above).
[eluser]MaxEisley[/eluser]
I have still problem with that, this is my model: Code: function getcar($id) { Controller: Code: $car = $this->data_model->getcar($this->input->post('Car')); all writes this is non object property. But when i write it in viewer like this, i got good result: Code: CT: |
Welcome Guest, Not a member yet? Register Sign In |