[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">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title><?php echo $setting['title']; ?></title>
</head>
<body>
<div id="header">
<a href="<?php echo $setting['location']; ?>"><img src="logo.jpg" /></a>
<p><?php echo $setting['tagline']; ?></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.