1

I have an array like this

  $meta = array(
       'meta_description' => 'lorem ipsum',
       'meta_keywords' => 'this, is, a, keyword'
  );

If I have this in my controller method, I can pass it to a partial like so: $this->template->set_partial('header', 'layouts/header', $meta) and it passes fine.

I store the meta tags in the database, so I'd ideally like to put it in MY_Controller and populate the array based on the database values for that post's meta tags.

If I move it outside of the controller method, I get Message: Undefined variable: meta as an error.

How can I make it globally available?

2 Answers 2

1

I think I figured it out.

I just created a new model for handling meta data, then I insert the following into MY_Controller's construct method:

 $meta = $this->meta_data_model->get_item_meta();

 $this->template->set_partial('header', 'layouts/header', $meta);

This seems to work fine, not sure if there is a better way of doing it.

Sign up to request clarification or add additional context in comments.

Comments

0

Anything you want to access globally should be stored in the user session:

$this->load->library('session'); // Unless auto loaded
$this->session->set_userdata('meta', $meta);

Then retrieve it where you need it:

$meta = $this->session->userdata('meta');

3 Comments

Isn't that for storing information about the user? This isn't related to users.
I dont think this is the best use of the userdata as it does not relate directly to the user and userdata can only store up to 4KB
Agreed. Userdata isn't the best given what he's trying to do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.