CodeIgniter Forums
loading view with dinamic data, best practices - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: loading view with dinamic data, best practices (/thread-37300.html)



loading view with dinamic data, best practices - El Forum - 01-05-2011

[eluser]skiff_pt[/eluser]
Hello all, I'm doing my first steps in CI, and therefore i would like have your opinion on the best practices.

In my current project I'm using a view with a defined structure (template) that loads dynamic data according to the url used.

This dynamic data is quite extensive array of strings.

Currently I'm storing these arrays as properties of my controller class, and i'm passing the correct array to the view after analyzing the url, and it works fine.

My Controller looks like this:
Code:
class Press_release extends Controller {
  
  private $data;
  private $tags = array (
                    'create' => array (
                        'event' => array(
                                          'heading_1' =>'Create',
                                          'heading_2' =>'Event'
                                         ),
                        'news'=> array(
                                          'heading_1' =>'Create',
                                          'heading_2' =>'News'
                                        )
                                      )
                
                         );                
                    

  function create($type){
    $this->data[]=$this->tags['create'][$type];
    
    $this->load->view('press_release');
  }

}

My View looks like this:
Code:
<h1>&lt;?php echo heading_1?&gt;</h1>
<h2>&lt;?php echo heading_2?&gt;</h2>


My problem is that my array with strings is getting too extensive and it makes my controller code very long. I would like to handle this dynamic data as separate php files where i only define the array with the strings (in my case one file for event, and another file for news), much like CI language files.

But without using include statements how can i do that in CI?

I tried to load the php files with the array from within my current view using both:
Code:
$this->load->view('dynamic_data');
and
Code:
$this->load->file('PATH_TO_VIEWS/dynamic_event_data');
but in both cases it seems the variables are not passed to the view.

What is the best practice to do something like this?
Can you please advise me?

Thanks in advance.