user2603785
user2603785

Reputation:

Codeigniter : Dynamic View


can you please tell how to access view components (div ...) from controller in Codeigniter, the purpose is to load profiles from database and show or hide some components according to the response and thank you.

Upvotes: 0

Views: 2105

Answers (2)

shapeshifter
shapeshifter

Reputation: 2967

See Adding Dynamic Data to the View,

https://www.codeigniter.com/userguide2/general/views.html

Upvotes: 0

greydnls
greydnls

Reputation: 342

Pass the variable from the controller into the view, and then determine whether or not to display sections of each profile. As an example:

Controller:

 $data['profile'] = $this->my_model->get_profile();

 $this->load->view('profileView', $data);

Then, in the view, you can test for values and display sections.

<?php if ($profile = "admin"){ ?>
<div id="AdminDiv">
Special Admin Content
</div>
<?php } ?>

Upvotes: 1

Related Questions