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
19 * <li><strong>CSSs, JSs:</strong> in config file 'article.php':
20 * an entry named "article_${method}_css" or "article_${method}_js"
21 * respectively with an array of .css or .js to be loaded into members $css
22 * and $js. It's up to the programmer to define how this members are going
26 * @category Base Controller Library
27 * @author Călin-Andrei Burloiu
29 class Article_Controller extends CI_Controller {
31 protected $title = NULL;
32 protected $metaDescription = NULL;
33 protected $helpers = array();
34 protected $libraries = array();
35 protected $css = array();
36 protected $js = array();
38 function __construct()
40 parent::__construct();
42 // Language, title and description
43 $this->lang->load('article');
45 // Helpers and libraries.
46 $this->config->load('article');
50 * Extend this with site specific information (header, menus...) and call
51 * $this->_load which is a generic method that loads the article.
52 * Both parameters must be passed to $this->_load.
54 public function _remap($method, $params = array())
57 $this->title = $this->lang->line("article_$method");
58 if ($this->title === FALSE)
59 $this->title = $method;
62 $this->metaDescription = $this->lang->line("article_${method}_description");
63 if ($this->metaDescription === FALSE)
64 $this->metaDescription = '';
67 $this->helpers = $this->config->item("article_${method}_helpers");
68 if ($this->helpers !== FALSE)
69 $this->load->helper($this->helpers);
72 $this->libraries = $this->config->item("article_${method}_library");
73 if ($this->libraries !== FALSE)
74 $this->load->library($libraries);
77 $css =& $this->config->item("article_${method}_css");
82 $js =& $this->config->item("article_${method}_js");
88 * Returns the article based on the language from
89 * "application/views/article/$language/$method".
91 * @param string $method defines article name
92 * @param array $params odd elements are keys and even elements are
93 * their values (eg.: [0] => key, [1] => value etc.). This are going to
94 * be converted to an associative array that is passed to the view if
95 * $assoc parameter is FALSE. Otherwise this parameter is already an
97 * @param bool $assoc states whether or not $params is associative
99 public function _load($method, $params = array(), $assoc = FALSE)
104 $params_assoc = array();
106 foreach ($params as $i => $val)
111 $params_assoc[$prev_val] = $val;
113 $alt = ($alt + 1) % 2;
117 $params_assoc = $params;
119 return $this->load->view('article/'. $this->config->item('language')
120 . '/' . $method, $params_assoc, TRUE);
124 /* End of file Article_Controller.php */
125 /* Location: ./application/core/Article_Controller.php */