考虑这种情况:: - 当我在管理员中上传视图文件时,在用户端创建一个新菜单,即动态创建菜单..
例如:当管理员上传帮助视图文件时,帮助菜单应出现在用户端..就是这样 可能,应该动态创建帮助控制器。
答案 0 :(得分:1)
当然,PyroCMS会这样做。看一下模块管理代码,特别是details.php。你需要自己做一些开发,但我的代码将演示我是如何完成的。
答案 1 :(得分:1)
我有这样的东西很容易回来......
看看我如何做到这一点的简单示例......这是一个帮助网站。
模特
<?php
class Template_model extends Model {
function Template_model()
{
parent::Model();
}
function load_pages()
{
$data = array();
$this->db->where('status',0);
$this->db->order_by('sort', 'ASC');
//$this->db->get('pages');
$query = $this->db->get('pages');
if ($query->num_rows() > 0){
foreach ($query->result_array() as $row){
$data[] = array(
"name" => $row['name'],
"url" => $row['url']
);
}
}
$query->free_result();
return $data;
}
}
控制器
<?php
class View extends Controller {
function View()
{
parent::Controller();
}
function index()
{
redirect('view/topic/orders');
//echo "oops";
}
function topic()
{
$page = $this->uri->segment(3);
//get the page id
$this->load->model('view_model');
$id = $this->view_model->get_page_id_by_url($page);
$id = $id['id'];
//get the page title
$data['title'] = $this->view_model->get_page_title($id);
//load the post by page id
$data['posts'] = $this->view_model->get_page_posts($id);
//load the header
$this->load->model('template_model');
$data['pages'] = $this->template_model->load_pages();
//load the view
$data['main_content'] = 'view/page';
$this->load->view('includes/template', $data);
}
function article()
{
$url = $this->uri->segment(3);
//get the post by url
$this->load->model('view_model');
$data['post'] = $this->view_model->get_post_by_url($url);
$id = $data['post']['page_id'];
//print_r($data['post']);
//get the page title
$data['title'] = $this->view_model->get_page_title($id);
//load the post by page id
$data['posts'] = $this->view_model->get_page_posts($id);
//load the header
$this->load->model('template_model');
$data['pages'] = $this->template_model->load_pages();
//load the view
$data['main_content'] = 'view/article';
$this->load->view('includes/template', $data);
}
}
/* End of file view.php */
/* Location: ./system/application/controllers/view.php */
和视图..
<div id="navigation">
<ul>
<?php
if(!empty($pages))
{
foreach($pages as $page)
{
?>
<li <?php if($on_page == $page['url']) { echo 'class="selected"'; }?>><a href="<?php echo base_url().'view/topic/'.$page['url'];?>"><?php echo $page['name'];?></a></li>
<?
}
}?>
<!-- top navigation use selected class for selected item -->
<div id="rNav" ><ul><li <?php if($on_page == 'admin') { echo 'class="selected"'; }?>><a href="<?php echo base_url();?>admin">Admin</a></li></ul></div>
<div id="rNav" ><ul><li <?php if($on_page == 'logout') { echo 'class="selected"'; }?>><a href="<?php echo base_url();?>logout">Logout</a></li></ul></div>
</ul>
</div>
答案 2 :(得分:0)
您应该将链接路由到处理菜单的特定控制器