Welcome Guest, Not a member yet? Register   Sign In
Help with helpers
#10

[eluser]gmask[/eluser]
[quote author="InsiteFX" date="1283288569"]What's wrong with using a MY_Controller?[/quote]
I don't understand.
Quote:As I see it, settings() should be in a model.

Helpers are more intended to be used in views (or if you need a simpler approach rather than object oriented).
Ok I see what you mean. I made the following changes:
my helper:
Code:
function settings()
{
    // Get global settings
    $CI = & get_instance();
    $query = $CI->db->get('settings');
    
    if ($query->num_rows() > 0)
    {
        $row = $query->row_array();
        $site['title'] = $row['title'];
        $site['tagline'] = $row['tagline'];
        $site['location'] = $row['location'];
        $site['comments'] = $row['comments_enable'];
    }
    return $site;
}
My view:
Code:
<?php $setting = settings(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html&gt;
&lt;head&gt;
    &lt;meta http-equiv="Content-type" content="text/html; charset=utf-8"&gt;
    &lt;title&gt;&lt;?php echo $setting['title']; ?&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
<div id="header">
    <a href="&lt;?php echo $setting['location']; ?&gt;"><img src="logo.jpg" /></a>
    <p>&lt;?php echo $setting['tagline']; ?&gt;</p>
</div>
And it all works. Is this the way you would do it? Essentially I just want to have a set of variables that I can call globally (because they are global blog settings).

Is there a way to do this better? Or at least a way to make the variables prettier? I'd like to be able to just call one variable for each, instead of the array thing. Like $site_title for the site title, etc.


Messages In This Thread
Help with helpers - by El Forum - 08-31-2010, 01:28 AM
Help with helpers - by El Forum - 08-31-2010, 02:05 AM
Help with helpers - by El Forum - 08-31-2010, 02:50 AM
Help with helpers - by El Forum - 08-31-2010, 03:11 AM
Help with helpers - by El Forum - 08-31-2010, 03:45 AM
Help with helpers - by El Forum - 08-31-2010, 04:04 AM
Help with helpers - by El Forum - 08-31-2010, 04:17 AM
Help with helpers - by El Forum - 08-31-2010, 04:37 AM
Help with helpers - by El Forum - 08-31-2010, 10:02 AM
Help with helpers - by El Forum - 08-31-2010, 12:41 PM
Help with helpers - by El Forum - 08-31-2010, 02:33 PM
Help with helpers - by El Forum - 09-01-2010, 01:42 AM



Theme © iAndrew 2016 - Forum software by © MyBB