Sending different data to multiple views

Someone recently asked me if they could send different data to different views in the same browser page and have the data displayed in its own section. Luckily, this can be done easily; you can pass more than one array of data to more than one view at the same time.

This can be really useful if your web page is split into sections with each section displaying its own data. For example, you may want a section displaying most read articles with another displaying most shared articles.

Getting ready

As we're going to be pulling data from a database we will need to ensure that a few config variables are set to allow us to do this. Open up the /path/to/codeigniter/application/config/database.php file and find the ...

Get CodeIgniter 2 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.