4

I'm having a little trouble updating a new client's pre-existing website from EE2.6 to 2.11.6. A now defunct add-on needs a few updates to work correctly with post 2.6 code formatting.

After some Googling I have replaced lines such as this one...

$this->EE->cp->set_variable('cp_page_title', lang('rsvp_email_attendees'));

with a 2.11.6 compatible equivalent, i.e.

$this->EE->view->cp_page_title =  lang('rsvp_email_attendees');

However, as a non add-on developer this particular part of the code has thrown me. Can you provide a suggestion as how I should format the following lines please.

$this->EE->cp->set_variable('cp_page_title', $data['event']['title']);
return $this->EE->load->view('event_details', $data, TRUE);

The "$data" part in the first line has thrown me, so I don't know how to format this correctly, and presumably it's being called in the second line.

Help greatly appreciated!

1
  • 1
    It will work same as above $this->EE->view->cp_page_title = $data['event']['title'];
    – Jainil
    Feb 15, 2017 at 14:06

1 Answer 1

3

You can create a function to set variable for backward compatibility like below :

function set_var($key, $val)
{
    if (version_compare(APP_VER, '2.6.0', '<'))
    {
        ee()->cp->set_variable($key, $val);
    }
    else
    {
        ee()->view->$key = $val;
    }
}

You can then use this function as below :

$this->set_var('cp_page_title', lang('rsvp_email_attendees'));

or

$this->set_var('cp_page_title', $data['event']['title']);

Check here for more information.

1
  • 2
    many thanks Jainil, your original post did the trick. I was expecting to have to change more than that - everything working okay now.
    – user1991
    Feb 15, 2017 at 17:05

Your Answer

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