CI框架与widget(页面布局) 出一份完善的代码
时间: 2024-06-09 11:05:31 浏览: 159
几个widget-android(框架及UI设计)
这里提供一个基于CodeIgniter框架和Bootstrap前端框架的页面布局示例:
1. 在CI框架中创建一个名为"app"的控制器(app.php),在其中定义一个名为"index"的方法,用于加载视图文件。
```php
class App extends CI_Controller {
public function index() {
$data['title'] = 'My Application';
$this->load->view('header', $data);
$this->load->view('navbar');
$this->load->view('sidebar');
$this->load->view('content');
$this->load->view('footer');
}
}
```
2. 创建一个名为"header.php"的视图文件,用于页面头部的内容。
```html
<!DOCTYPE html>
<html>
<head>
<title><?php echo $title; ?></title>
<link rel="stylesheet" href="<?php echo base_url('assets/css/bootstrap.min.css'); ?>">
</head>
<body>
```
3. 创建一个名为"navbar.php"的视图文件,用于页面顶部的导航栏。
```html
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">My Application</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
</ul>
</div>
</nav>
```
4. 创建一个名为"sidebar.php"的视图文件,用于页面左侧的侧边栏。
```html
<div class="container-fluid">
<div class="row">
<nav class="col-md-2 d-none d-md-block bg-light sidebar">
<div class="sidebar-sticky">
<ul class="nav flex-column">
<li class="nav-item">
<a class="nav-link active" href="#">
<span data-feather="home"></span>
Dashboard <span class="sr-only">(current)</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<span data-feather="file"></span>
Orders
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<span data-feather="shopping-cart"></span>
Products
</a>
</li>
</ul>
</div>
</nav>
</div>
</div>
```
5. 创建一个名为"content.php"的视图文件,用于页面中间的内容区域。
```html
<main role="main" class="col-md-9 ml-sm-auto col-lg-10 px-4">
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
<h1 class="h2">Dashboard</h1>
<div class="btn-toolbar mb-2 mb-md-0">
<div class="btn-group mr-2">
<button type="button" class="btn btn-sm btn-outline-secondary">Share</button>
<button type="button" class="btn btn-sm btn-outline-secondary">Export</button>
</div>
<button type="button" class="btn btn-sm btn-outline-secondary dropdown-toggle">
<span data-feather="calendar"></span>
This week
</button>
</div>
</div>
<canvas class="my-4" id="myChart" width="900" height="380"></canvas>
<h2>Section title</h2>
<div class="table-responsive">
<table class="table table-striped table-sm">
<thead>
<tr>
<th>#</th>
<th>Header</th>
<th>Header</th>
<th>Header</th>
<th>Header</th>
</tr>
</thead>
<tbody>
<tr>
<td>1,001</td>
<td>Lorem</td>
<td>ipsum</td>
<td>dolor</td>
<td>sit</td>
</tr>
</tbody>
</table>
</div>
</main>
```
6. 创建一个名为"footer.php"的视图文件,用于页面底部的内容。
```html
<script src="<?php echo base_url('assets/js/jquery-3.3.1.slim.min.js'); ?>"></script>
<script src="<?php echo base_url('assets/js/popper.min.js'); ?>"></script>
<script src="<?php echo base_url('assets/js/bootstrap.min.js'); ?>"></script>
</body>
</html>
```
7. 将Bootstrap和jQuery的文件放到CI框架的"assets"文件夹中。
8. 访问"http://yourdomain.com/app"即可看到页面布局效果。
以上代码仅作为示例,具体的页面布局可以根据实际需求进行调整和修改。
阅读全文