php - CodeIgniter get_where -


I am trying to use get_where to get a list of all database records where the owner login equals the user is.

This is my job in my controller;

  function files () {$ owner = $ this- & gt; Auth-> Get_user (); $ This- & gt; Db- & gt; Get_where ('file', array ('owner =' = & gt; 'owner')) - & gt; result (); }  

And in my opinion I have the following;

  & amp; Php foreach ($ query- & gt; result () as the $ line):? & Gt; & Lt; Period & gt; & Lt ;? = $ Row-> Name & gt ;? & Lt; / Span & gt; & Lt ;? Php endforeach; ? & Gt;  

When I try to access the scene, I get a fatal error: Call the result of a member function () on line / 1 / views / account / files.php On non-object.

Thanks

There is a framework based on codeigner principles. Consequently, you will typically use application logic, data separation, and "output" in your respective areas for codeigner use. In this case: controllers, models and ideas.

For just reference, you should generally have a "data" code as a model function, in this situation get_where functionality I highly recommend that you have been provided to catch up with CodeIgniter Through mediums, it should hold your hand through the most stages. See: Topic table (top right).

TL; DR

To solve your problem, you need to make sure that you pass the controller variable through your view:

  function Files () $ owner = $ this- & gt; Auth-> Get_user (); $ Data ['files'] = $ this- & gt; Db- & gt; Get_where ('files', array ('owner =' = & gt; 'owner')) - & gt; result (); $ This- & gt; Load-> View ('name_of_my_view', $ data); }  

and then make sure to use the correct variable in your view:

  & lt; Php foreach ($ files as $ rows):? & Gt; & Lt; Period & gt; & Lt ;? = $ Line ['name']; ? & Gt; & Lt; / Span & gt; & Lt ;? Php endforeach; ? & Gt;  

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -