1 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
3 * Library Article_Controller can be extended by a controller to be used for
4 * content pages that depend on the language.
6 * The page views are usually located in
7 * "application/views/article/$language/$method".
10 * <li><strong>Article Title:</strong> in language file 'article_lang.php':
11 * an entry named "article_$method".
12 * If not present "$method" is used as a name.</li>
13 * <li><strong>Article Meta Description:</strong> in language file..:
14 * an entry "article_${method}_description"</li>
15 * <li><strong>Helpers, Libraries:</strong> in config file 'article.php':
16 * an entry named "article_${method}_helpers" or "article_${method}_libraries"
17 * respectively with an array of helpers or libraries to be loaded for the
21 * @category Base Controller Library
22 * @author Călin-Andrei Burloiu
24 class Article_Controller extends CI_Controller {
26 protected $title = NULL;
27 protected $metaDescription = NULL;
28 protected $helpers = array();
29 protected $libraries = array();
31 function __construct()
33 parent::__construct();
35 // Language, title and description
36 $this->lang->load('article');
38 // Helpers and libraries.
39 $this->config->load('article');
43 * Extend this with site specific information (header, menus...) and call
44 * $this->_load which is a generic method that loads the article.
45 * Both parameters must be passed to $this->_load.
47 public function _remap($method, $params = array())
50 $this->title = $this->lang->line("article_$method");
51 if ($this->title === FALSE)
52 $this->title = $method;
55 $this->metaDescription = $this->lang->line("article_${method}_description");
56 if ($this->metaDescription === FALSE)
57 $this->metaDescription = '';
60 $this->helpers = $this->config->item("article_${method}_helpers");
61 if ($this->helpers !== FALSE)
62 $this->load->helper($this->helpers);
65 $this->libraries = $this->config->item("article_${method}_library");
66 if ($this->libraries !== FALSE)
67 $this->load->library($libraries);
71 * Returns the article based on the language from
72 * "application/views/article/$language/$method".
74 * @param string $method defines article name
75 * @param array $params odd elements are keys and even elements are
76 * their values (eg.: [0] => key, [1] => value etc.). This are going to
77 * be converted to an associative array that is passed to the view if
78 * $assoc parameter is FALSE. Otherwise this parameter is already an
80 * @param bool $assoc states whether or not $params is associative
82 public function _load($method, $params = array(), $assoc = FALSE)
87 $params_assoc = array();
89 foreach ($params as $i => $val)
94 $params_assoc[$prev_val] = $val;
96 $alt = ($alt + 1) % 2;
100 $params_assoc = $params;
102 return $this->load->view('article/'. $this->config->item('language')
103 . '/' . $method, $params_assoc, TRUE);
107 /* End of file Article_Controller.php */
108 /* Location: ./application/core/Article_Controller.php */