Welcome Guest, Not a member yet? Register   Sign In
errors in execution
#1

[eluser]Unknown[/eluser]
Please I need help with this code
This is the error that occurs when running

ERROR
Fatal error: Call to a member function result() on a non-object in C:\wamp\www\mobilestore\application\views\cliente.php on line 4


CONTROLLER
class ClienteController extends CI_Controller {
public function index() {
}

public function search($id) {
// echo ('estamos aqui');
$this->load->model('Cliente_Model');
$data['contenido'] = $this->Cliente_Model->search1($id);
$data['title'] = 'Relacion de Clientes';
$data['main_content'] = 'cliente';
$this->load->view('includes/template_general', $data);
}

}


MODEL

class Cliente_Model extends CI_Model{

//Public var $id1 = "";

function __construct(){
// Call the Model constructor
parent::__construct();
}

Public function search1($id){
echo ($id);
$this->db->select('intClienteId , varRazonSocial, varLogoCliente, varDireccion, varTelefono1Cliente, varCorreo1Cliente, varURL1Cliente');
$this->db->where('varTipo1ClienteId',$id);
$query = $this->db->get('tb_cliente');
if ($query -> num_rows>0){
return $query->result();
}else {
return FALSE;
}

}


}

VIEWS
1
2 <ul data-role="listview" data-inset="true" data-theme="c" data-dividertheme="b" data-filter="true">
3 <li data-role="list-divider" data-corners="true" data-inline="true" >&lt;?php echo $title?&gt;</li>
4 &lt;?php foreach ($contenido->result() as $item):?&gt;
5 <li data-ic>&lt;?php echo anchor('clientecontroller/search/?id='.$item-&gt;intClienteId.'',$item->varRazonSocial);?&gt;<span class="ui-li-count">0</span></li>
6 &lt;?php endforeach;?&gt;
7 </ul>
#2

[eluser]PhilTem[/eluser]
Your model returns

Code:
$query->result();

which is an array of objects.

You are calling

Code:
$contenido->result()

in your view is basically the same as calling

Code:
$query->result()->result();

meaning that every result from the database has a method called result(). Which is very unlikely to be correct.

What you would need to do, besides using [ code ] blocks (without the spaces) in future posts, is replacing your foreach in the view with

Code:
&lt;?php foreach ( $contenido as $item ) : ?&gt;

and it should work.




Theme © iAndrew 2016 - Forum software by © MyBB