[eluser]Mike Cocklin[/eluser]
I know that I must be doing something stupid but I am having no joy in adding my own helper to my controller and using the helper functions.
Here is my controller
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Welcome extends CI_Controller {
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see http://ellislab.com/codeigniter/user-guide/general/urls.html
*/
public function __construct()
{
parent::__construct();
$this->load->model('Page_model');
$this->load->helper('content');
}
// function getTitle($pageName)
// {
// $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 5); //Gets browser language
// $pageTitle = $pageName . '.title';
//
// $data['pageTitle'] = $this->Page_model->page_data($options = array('getKey' => $pageTitle, 'locale' => $lang));
//
// return $data['pageTitle'];
//
// }
//
// function getContent($pageName)
// {
// $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 5);
// $pageContent = $pageName . '.content';
//
// $data['pageContent'] = $this->Page_model->page_data($options = array('getKey' => $pageContent, 'locale' => $lang));
// //print_r($data['pageContent']);
// //die();
// return $data['pageContent'];
// }
public function index()
{
echo 'You are here okay' . '<br />';
$test['array'] = $this->getTitle('welcome_message');
print_r($test['array']);
die();
$data['page_title'] = $this->getTitle('welcome_message');
$data['page_content'] = $this->getContent('welcome_message');
$this->load->view('templates/header', $data);
$this->load->view('templates/sidebar');
$this->load->view('templates/banner');
$this->load->view('templates/rightcol');
$this->load->view('pages/welcome_message', $data);
$this->load->view('templates/footer');
}
As you can see I commented out two functions so that I could move them to a helper as I need to call these functions from several controllers.
My helper looks like this now.
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
if ( ! function_exists('getTitle'))
{
function getTitle($pageName)
{
$this->load->model('Page_model'); /*Loads page_model*/
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 5); /*Gets browser language*/
$pageTitle = $pageName . '.title';
$data['pageTitle'] = $this->Page_model->page_data($options = array('getKey' => $pageTitle, 'locale' => $lang));
return $data['pageTitle'];
}
}
if ( ! function_exists('getContent'))
{
function getContent($pageName)
{
$this->load->model('Page_model');
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 5);
$pageContent = $pageName . '.content';
$data['pageContent'] = $this->Page_model->page_data($options = array('getKey' => $pageContent, 'locale' => $lang));
return $data['pageContent'];
}
}
/* End of file content_helper.php */
/* Location: ./system/helpers/content_helper.php */
However I get absolutely nothing back and in fact it seems I am not even hitting my helper function, though I am getting into the helper
please someone, rescue me from misery!!!