• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Things to Configure Before Coding?

#11
I would also recommend adding an /application/config/application.php file which I would add to $autoload['config']. That way, you can keep any application-specific configuration separate from the CI config files and still have the data (almost) as readily available as the values in the /application/config/config.php file.

You should consider moving most of the helpers/libraries you're autoloading to your base controller's constructor. At some point you may find instances in which you want to prevent something from being loaded, and it will be much easier to do so if they're loaded by a controller than if they are in the autoload config. I have database in $autoload['libraries'] and url & language in $autoload['helper'], but I've gone back and forth considering whether I even need that much.
Reply

#12
(07-27-2015, 08:54 AM)mwhitney Wrote: I would also recommend adding an /application/config/application.php file which I would add to $autoload['config']. That way, you can keep any application-specific configuration separate from the CI config files and still have the data (almost) as readily available as the values in the /application/config/config.php file.

You should consider moving most of the helpers/libraries you're autoloading to your base controller's constructor. At some point you may find instances in which you want to prevent something from being loaded, and it will be much easier to do so if they're loaded by a controller than if they are in the autoload config. I have database in $autoload['libraries'] and url & language in $autoload['helper'], but I've gone back and forth considering whether I even need that much.

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...
No SEO spam
Reply

#13
I tried this step below,
http://avenir.ro/codeigniter-tutorials/v...ything-ok/

Incorporated it under HMVC installation.
And created a module called self_check
and renamed the verify.php controller into self_check


Code:
application/modules/self_check
   /controllers
     /self_check.php
   /models
     ...no files here
   /views
     /verify_view.php


And I run it and it works.
This self_check is very cool, I think we need to improve it and include it in next release of CI.
What do you think guys?
No SEO spam
Reply

#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

#15
@mwhitney

Thank you, very much appreciated.
No SEO spam
Reply

#16
How about load session when users login cause i feel wasting time to write session every single controller !
Reply

#17
@freddy

you can autoload that in autoload.php
No SEO spam
Reply

#18
(07-29-2015, 09:51 PM)freddy Wrote: How about load session when users login cause i feel wasting time to write session every single controller !

Waste of time is the wrong reasoning, but in fact sessions should be started on login.
Reply

#19
(07-25-2015, 06:55 AM)Wouter60 Wrote: Step 1 (remove index.php): if you do that, your CodeIgniter site won't work at all.
You probably mean to say that you want to use URL's without index.php in it. That's what you do in step 2 (.htaccess).

Step 6: Put your assets (images, stylesheets, javascripts) in the right place where CodeIgniter can find them.
Step 7: Configure the session driver you want to use (files or database)

+1 for step # 6. I usually do that.
Reply

#20
(07-29-2015, 09:51 PM)freddy Wrote: How about load session when users login cause i feel wasting time to write session every single controller !

Create a base controller (e.g. MY_Controller) which loads the session library. If you need it to be loaded only under certain conditions, you can add a property which controls whether the library is loaded, then set it accordingly. For example, you could create a protected property called $loadSession and default it to TRUE, then a controller which shouldn't load the session can override the property and set it to FALSE.

PHP Code:
class MY_Controller extends CI_Controller
{
    protected $loadSession TRUE;

    public function __construct()
    {
        parent::__construct();
        if ($this->loadSession) {
            $this->load->library('session');
        }
    }


PHP Code:
class Cli_controller extends MY_Controller
{
    protected $loadSession FALSE;

    public function __construct()
    {
         parent::__construct();
    }

Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.