Messing Arround With CI |
[eluser]Rost[/eluser]
I am messing around with CI, but stood on a problem. When I am trying to echo my sitetitle I get a error: Quote:<h4>A PHP Error was encountered</h4> This line is: Code: <title><?=$s->f_sitetitle; ?></title> The Model's code is: Code: function getSettings(){ The Controllers code is: Code: function index() I can't solve it, trying the whole morning. I hope you can help me
[eluser]garymardell[/eluser]
You are returning the results as an array but using it like a object. Use this: Code: function getSettings(){ That should make your code work as it is. You should also note that i believe it good practice to return the whole get() object back if you are getting results. Code: function getSettings(){ Code: function index() then in the view you can do: Code: <? if($s->num_rows() > 0): ?> This way your view has access to the num rows function which allows you to display items such as "you do not have any posts" or else display the posts.
[eluser]Dam1an[/eluser]
I'm guessing $s is never set to anything as the qiery doesn't return anything? (aka doesn;t make it in the foreach loop) Try doing var_dump on the variable to see what you get
[eluser]Rost[/eluser]
When using var_dump($s) I am getting: Code: array(1) { And @Gary, the code you provide me doesnt work. I am getting the error: Quote:Fatal error: Call to a member function num_rows() on a non-object in /var/www/vhosts/rstevens.eu/httpdocs/system/application/views/index.php on line 5 EDIT: @Gary it works, but cant it be shorter?
[eluser]Dam1an[/eluser]
the problem is you're returning an array of results, instead of a single row If you only ever expect a single result, use ->row() instead Otherwise, call it as follows Code: <title><?=$s[0]->f_sitetitle; ?></title> Notice you're calling the f_sitetitle variable on the first object in the array
[eluser]Rost[/eluser]
It works thank you very much I would never come with that idea.
[eluser]Dam1an[/eluser]
You're welcome And if something ever isn;t what it seems, var_dump is your friend |
Welcome Guest, Not a member yet? Register Sign In |