[eluser]Unknown[/eluser]
I'm very new to CodeIgniter and I'm trying to get a hang of it. Recently I discovered icon fonts, which would come in handy since I'm not a graphics geek myself and I dislike real images on websites.
This morning I started writing an icon font helper for use in controllers. My reason for this is that in the future I maybe would like to switch my preferred icon font, but I don't want to change hundreds of hardcoded characters in all my views.
The current layout of my icon font helper is the following:
Code:
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
if (!function_exists('entypo')) {
function entypo() {
$entypo = array(
'dl' => 'w',
'edit' => '&',
'heart' => '6',
'info' => '`',
'quote' => ';',
'star' => '7',
'ul' => 'v'
);
if (func_num_args() > 0) {
if (is_array(func_get_arg(0))) {
$args = func_get_arg(0);
} else {
$args = func_get_args();
}
}
foreach ($entypo as $key => $char) {
if (in_array($key, $args)) {
$chars[$key] = $entypo[$key];
}
}
return $chars;
}
}
It is far from complete, but I'm using it like this in my controller:
Code:
<?php
class Blog extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->model('blog_model');
}
public function index() {
$this->load->helper('typography');
$this->load->helper('icon_font');
$data['title'] = 'Blog';
$data['blog_posts'] = $this->blog_model->get_blog_posts();
$data['icons'] = entypo('edit', 'star', 'heart');
$this->load->view('templates/header', $data);
$this->load->view('blog/view', $data);
$this->load->view('templates/footer', $data);
}
}
And then in my view:
Code:
<?php foreach ($blog_posts as $blog_post): ?>
<article class="blog-post">
<h2><span class="icon"><?php echo $icons['star'] ?></span><? echo $blog_post['title'] ?></h2>
<? echo auto_typography($blog_post['content']) ?>
</article>
<?php endforeach ?>
The CSS class "icon" is set to use the @font-face rule for the chosen font, Entypo. Is this whole thing stupid? Am I stupid? (You may correct me on some other code errors as I'm quite new to CodeIgniter.)