How to create a widget system in Codeigniter

后端 未结 2 835
谎友^
谎友^ 2021-02-02 17:00

I am creating a custom CMS in Codeigniter and I\'d like to have a widget system similar to what is used in Wordpress.

For example, I\'d like to have a widget that shows

2条回答
  •  感情败类
    2021-02-02 17:41

    What if you want to see some widgets in some controllers? In my opinion, something basic and simple is to keep the widgets of the CMS in a database with the name and a boolean active and inactive.

    Finally, in a query, you get an array of widgets. We can extend the main controller and display all the default widgets (using an array, and a global variable)

    cms_widget = array(
            'msg'   => TRUE,
            'chat'  => TRUE,
            'video' => TRUE,
            'games' => TRUE
            );  
        }
    
    }
    

    When you call the template of your CMS, you should make a conditional all your widgets to appear in the desired location. For example in column view template:

    if($this->cms_widget['msg']) $this->load->view('widget/msg_view');
    if($this->cms_widget['chat']) $this->load->view('widget/chat_view');
    if($this->cms_widget['video']) $this->load->view('widget/video_view');
    if($this->cms_widget['games']) $this->load->view('widget/games_view');
    

    Now, for example. If you are in sight "Games", will show only the corresponding widget. Suppose I want to see the widget "Games" and "Videos". We would only have to disable the remaining widgets

    cms_widget = array_merge($this->cms_widget, array(
    
                                    'msg'   => FALSE,
                                    'chat'  => FALSE
                                                                        ));
    
                    $this->load->view('game_view');
                }
            }
    
        }
    

提交回复
热议问题