• Data available for all views in codeigniter

    Set in application/config/autoload.php
    $autoload['libraries'] = array('config_loader');
    Create application/libraries/Config_loader.php
    defined('BASEPATH') OR exit('No direct script access allowed.');
    
    class Config_loader
    {
        protected $CI;
    
        public function __construct()
        {
            $this->CI =& get_instance(); //read manual: create libraries
    
            $dataX = array(); // set here all your vars to views
    
            $dataX['titlePage'] = 'my app title';
            $dataX['urlAssets'] = base_url().'assets/';
            $dataX['urlBootstrap'] = $dataX['urlAssets'].'bootstrap-3.3.5-dist/';
    
            $this->CI->load->vars($dataX);
        }
    }
    on your views
    <title><?php echo $titlePage; ?></title>
    <!-- Bootstrap core CSS -->
    <link href="<?php echo $urlBootstrap; ?>css/bootstrap.min.css" rel="stylesheet">
    <!-- Bootstrap theme -->
    <link href="<?php echo $urlBootstrap; ?>css/bootstrap-theme.min.css" rel="stylesheet">
  • 0 comments:

    Post a Comment

    FAVOURITE LINE

    To steal ideas from one is plagiarism. To steal from many is Research.

    ADDRESS

    Mumbai , Maharashtra

    EMAIL

    shikha.pathak6@gmail.com
    shikha.the.swt.pari@gmail.com

    Skype

    shikha_pari