Welcome Guest, Not a member yet? Register   Sign In
Creating dynamic block
#1

[eluser]jabga[/eluser]
Hi all. I am creating a small web and it has a admin panel (add, edit, delete news, users etc). Now I would like to be able to create html block (for joomla:module, for wordpress:widget) from admin.

I am thinking about how to handle it. Please help me on this.

I guess I should call block view from main view.
For example
main view code:
Code:
<div id="leftColumn">
$this->load->view('block1');
$this->load->view('block2');
</div>

I guess I will have to write the code which retrieves block details from database in the view. I think it's not good idea.
Thanks
#2

[eluser]Boris Strahija[/eluser]
You could declare an array variable in the controller that holds all the views for all the widgets.

Controller:
Code:
$data['widgets'] = array('widgets/box1', 'widgets/box2', 'widgets/box3');
$this->load->view('main', $data);

Then in your main view do this:
Code:
if (isset($widgets)) :
    foreach ($widgets as $widget) :
        $this->load->view($widget);
    endforeach;
endif;
#3

[eluser]jabga[/eluser]
Thanks, and where should I write Active Records ? (get widget details from Database)
#4

[eluser]Boris Strahija[/eluser]
I'm not sure I quite understand what you're trying to do. Do you save the HTML for the widgets into the database?
Or do you just want to load specific views into your main view?
How does the DB table for your widgets look like?
#5

[eluser]jabga[/eluser]
Thanks a lot for your reply.
I think my ci_block table will look like it:
Code:
id
title
position
content
enabled
and I my design, there are 5 block positions. For example
id:1
title:Quick contact
position: right1
content: < contact us view here >
enabled: 1


Smile
Can I use model in the view? I think it's not good idea, please help me thanks




Theme © iAndrew 2016 - Forum software by © MyBB