[英]Sidemenu In codeigniter
I just try to bulid control panel using MVC (codeigniter), I just need way to how make a side menu in home page and when I click in the link in menu the page open in the right side, and the menu stay in the left side. 我只是尝试使用MVC(codeigniter)构建控制面板,我只需要在主页上创建侧边菜单的方法,当我单击菜单中的链接时,页面将在右侧打开,菜单留在左侧侧。
I need coorect way to do this using MVC. 我需要使用MVC的coorect方法。
I use this simple way to make Views to make exactly what your asking. 我使用这种简单的方法使View完全符合您的要求。
<?php
//This is mainpage.php
$data['page_id'] = $_GET['page_id'];
?>
<!DOCTYPE HTML>
<html>
<head>
<title></title>
</head>
<body>
<div>
<!-- HERE Comes Side Bar -->
<?php $this->load->view('sidebar'); ?>
</div>
<div>
<!-- HERE Comes Main Content -->
<?php $this->load->view('maincontent',$data) ?>
</div>
</body>
</html>
Mainpage.php is a master page who holds code for both, side menu as well as the content page Mainpage.php是一个母版页,其中包含侧菜单和内容页的代码
This code if for side bar sidebar.php in view folder 此代码是否用于查看文件夹中的侧栏sidebar.php
<div>
<ul>
<li><a href="somelink/?page_id=dashboard">Dashboard</a></li>
<li><a href="somelink/?page_id=settings">Settings</a></li>
<li><a href="somelink/?page_id=logout">Logout</a></li>
</ul>
</div>
sidebar.php page only holds different links, but all links have GET variable named "page_id" which decides which page is to be displayed in the content page. sidebar.php页面仅包含不同的链接,但是所有链接都具有名为“ page_id”的GET变量,该变量决定要在内容页面中显示哪个页面。
Now, in mainpage.php you can notice that maincontent.php is loaded as view with passing $data which has page_id as variable, which is drived from sidebar. 现在,在mainpage.php中,您会注意到maincontent.php已作为视图加载,并传递了$ data,该数据具有page_id作为变量,是从侧边栏驱动的。 this will help to display the content in content side.
这将有助于在内容侧显示内容。
This code is for maincontent.php in view folder 此代码用于view文件夹中的maincontent.php
<?php
if(file_exists(APPPATH.'views/'.$page_id.'.php')){
$this->load->view($page_id);
}else{
show_404();
}
this has always worked for me in non ajax page displays...so will work for you to. 这在非ajax页面显示中一直对我有用...因此将对您有用。 Thanks...
谢谢...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.