Welcome Guest, Not a member yet? Register   Sign In
Things to Configure Before Coding?
#14

(07-28-2015, 03:15 AM)solidcodes Wrote: Can you show as example snippet codes of application.php for the benefit of all. 
Or perhaps can you show us, how did you do it step by step tutorial please.
Interesting...

In /application/config/autoload.php:
PHP Code:
$autoload['config'] = array('application'); 

Then create a file in /application/config named application.php. Put any configuration entries which are specific to your application in this file. For example:
PHP Code:
$config['site.title'] = 'This is a default title for my pages';
$config['site.system_email'] = '[email protected]';
$config['site.list_limit'] = 25;
$config['site.default_user_timezone'] = 'America/Los_Angeles'

You can see a more detailed example in Bonfire's version of the file.

These would all be settings you want available for your application. Some of the settings I included in my example used to be in Bonfire's version of the file, but are now in a settings module which stores the settings in the database and adds a user interface for site admins to change the settings, but there are still plenty of settings in Bonfire's application config.

Bonfire's base controller includes its own "autoload" functionality to simplify moving certain types of files (libraries, helpers, and models) from the autoload config. It's important to note, though, that these are loaded later than CI's autoload, so there are some cases where this wouldn't be appropriate.

PHP Code:
class MY_Controller extends CI_Controller 
{
    public $autoload = array(
        'libraries' => array('events'),
        'helpers' => array('application'),
        'models' => array(),
    );

    public function __construct()
    {
        parent::__construct();
        $this->autoload_classes();
    }

    public function autoload_classes()
    {
        if (! empty($this->autoload['libraries']) && is_array($this->autoload['libraries'])) {
            foreach ($this->autoload['libraries'] as $library) {
                $this->load->library($library);
            }
        }
        if (! empty($this->autoload['helpers']) && is_array($this->autoload['helpers'])) {
            foreach ($this->autoload['helpers'] as $helper) {

                $this->load->helper($helper);
            }
        }
        if (! empty($this->autoload['models']) && is_array($this->autoload['models'])) {
            foreach ($this->autoload['models'] as $model) {
                $this->load->model($model);
            }
        }
    }

Reply


Messages In This Thread
RE: Things to Configure Before Coding? - by mwhitney - 07-29-2015, 07:01 AM
RE: Things to Configure Before Coding? - by Narf - 07-30-2015, 01:36 AM



Theme © iAndrew 2016 - Forum software by © MyBB