创建视图

admin 发表于 2018-05-14 18:49 上一篇

首页 > 技术文档 > 开发一个模块

创建视图
发表于 2018-05-14 18:49

在 views 文件夹,我们创建一个跟控制器名称一样的文件夹list,新建一个index.php的视图文件。

我们讨论过多次,最后决定IBOS的视图机制还是以高效为主。因此我们没有使用模板,而是直接使用了原生的PHP。因此一个视图文件便是一个PHP文件。

为了演示方便,这次的视图使用了全局的layout,样式也是全局的。在大多数情况下应该能满足需求。当然你也可以设计模块独有的风格,使用模块独有的样式。

注:全局的layout文件放在 system\theme\default\views\layouts\main.php。这个 layout 包含了头尾,中间的部分就是index.php 里的内容。

随后,我们输入以下内容:

index.php

<!-- Mainer -->
<div class="mc clearfix">
    <!-- Mainer right -->
    <div>
        <div class="page-list">
            <div class="page-list-header">
                <div class="btn-toolbar pull-left">
                    <div class="btn-group">
                        <a class="btn" <?php echo $this->createUrl( 'content/add' ); ?>>增加留言</a>
                        <a class="btn" <?php echo $this->createUrl( 'content/del' ); ?>>删除留言</a>
                    </div>
                </div>
            </div>
            <div class="page-list-mainer">
                <?php if ( count( $list ) > 0 ): ?>
                    <table class="table table-striped table-hover">
                        <thead>
                            <tr>
                                <th><label class="checkbox"><input type="checkbox" data-name="message"></label></th>
                                <th>留言人</th>
                                <th>时间</th>
                                <th>内容</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php foreach ( $list as $index => $row ): ?>
                                <tr>
                                    <td width="20">
                                        <label class="checkbox">
                                            <input type="checkbox" name="message" value="<?php echo $row['id']; ?>">
                                        </label>
                                    </td>
                                    <td><?php ?></td>
                                    <td><?php echo ConvertUtil::formatDate( $row['time'], 'u' ); ?></td>
                                    <td><?php echo $row['content']; ?></td>
                                    <td>
                                        <?php if ( $row['uid'] == Ibos::app()->user->uid ): ?>
                                            <a class="btn btn-small" <?php echo $this->createUrl( 'content/del', array( 'id' => $row['id'] ) ); ?>>删除</a>
                                            <a class="btn btn-small" <?php echo $this->createUrl( 'content/edit', array( 'id' => $row['id'] ) ); ?>>编辑</a>
                                        <?php endif; ?>
                                        <a class="btn btn-small" <?php echo $this->createUrl( 'content/reply', array( 'id' => $row['id'] ) ); ?>>回复</a>
                                    </td>
                                </tr>
                            <?php endforeach; ?>
                        </tbody>
                    </table>
                </div>
                <div class="page-list-footer">
                    <div class="pull-right">
                        <?php $this->widget( 'IWPage', array( 'pages' => $pages ) ); ?>
                    </div>
                </div>
            <?php else: ?>
                <div class="no-data-tip"></div>
            <?php endif; ?>
        </div>
    </div>
</div>

这个视图里的逻辑应该不难理解。

我们先跳过这个视图里出现的陌生的方法,打开浏览器,输入 {你的IBOS访问地址}/?r=messageboard/list/index,看看页面是不是出来了?

现在还没有任何内容,因为我们还没写添加及其他的方法。但是到这里,已经没有什么难题了,你基本需要了解的已经了解了。

以上信息是否对您有帮助?
0.0244s