CodeIgniter: global variables in a controller

前端 未结 5 1232
一整个雨季
一整个雨季 2020-12-24 13:56

I\'m a very newbie on CodeIgniter, and while I go on I run into problems that, in the procedural coding, were easy to fix

The current issue is: I have this controlle

5条回答
  •  死守一世寂寞
    2020-12-24 14:34

    Why not user a helper?

    File:

    /application/helpers/meta_helper.php
    

    Content:

     null, "robots" => "noindex, nofollow" );
    }
    

    In your controller:

    class Basic extends Controller {
    
        function __construct(){
            parent::__construct();
            $this->load->helper('meta');
        }    
    
        function index(){
            $data['meta'] = meta_data(); //associate the array on it's own key;
    
            //if you want to assign specific value
            $data['meta']['title'] = 'My Specific Page Title';
    
            //all other values will be assigned from the helper automatically
    
            $this->load->view('basic_view', $data);
        }
    

    And in your view template:

     <?php $meta['title']; ?>
    

    Will output:

    My Specific Page Title
    

    Hope that makes sense :-)!

提交回复
热议问题