Viewed   94 times

I need to loop lot of arrays in different ways and display it in a page. The arrays are generated by a module class. I know that its better not to include functions on 'views' and I want to know where to insert the functions file.

I know I can 'extend' the helpers, but I don't want to extend a helper. I want to kind of create a helper with my loop functions.. Lets call it loops_helper.php



A CodeIgniter helper is a PHP file with multiple functions. It is not a class

Create a file and put the following code into it.

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

if ( ! function_exists('test_method'))
    function test_method($var = '')
        return $var;

Save this to application/helpers/ . We shall call it "new_helper.php"

The first line exists to make sure the file cannot be included and ran from outside the CodeIgniter scope. Everything after this is self explanatory.

Using the Helper

This can be in your controller, model or view (not preferable)


echo test_method('Hello World');

If you use this helper in a lot of locations you can have it load automatically by adding it to the autoload configuration file i.e. <your-web-app>applicationconfigautoload.php.

$autoload['helper'] = array('new_helper');


Monday, September 12, 2022

This is a know issue in CodeIgniter 3.0.0, see the github issue here and changelog below:

Fixed a bug (#4137) - :doc:Error Handling <general/errors> breaks for the new Error exceptions under PHP 7.

It's because set_exception_handler() changed behavior in PHP 7.

Code that implements an exception handler registered with set_exception_handler() using a type declaration of Exception will cause a fatal error when an Error object is thrown.

If the handler needs to work on both PHP 5 and 7, you should remove the type declaration from the handler, while code that is being migrated to work on PHP 7 exclusively can simply replace the Exception type declaration with Throwable instead.

// PHP 5 era code that will break.
function handler(Exception $e) { ... }

// PHP 5 and 7 compatible.
function handler($e) { ... }

// PHP 7 only.
function handler(Throwable $e) { ... }

Upgrading to anything beyond 3.0.2 will fix your issue.

Friday, December 9, 2022

You can get instance:

 $CI =& get_instance();

After that you will be able to use $CI->db for queries..

Friday, December 16, 2022

Make sure you have correct domain set in /application/config/config.php at $config['cookie_domain']

Thursday, November 3, 2022

I think the problem is with short tags,

<?php include 'header.php';?>

But i would say, in codeigniter use,

Wednesday, October 5, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :