在我的视图页面上使用HMVC的codeigniter项目中,$ class显示不正确。当我尝试查看我的模块时,如果没有列左或右,则应该转到 col-sm-12
出于某种原因,如果没有列左侧或右侧,它应显示 col-sm-9 col-sm-12 。
<?php echo $header; ?>
<div class="container">
<div class="row"><?php echo $column_left; ?>
<?php if ($column_left && $column_right) { ?>
<?php $class = 'col-sm-6'; ?>
<?php } elseif ($column_left || $column_right) { ?>
<?php $class = 'col-sm-9'; ?>
<?php } else { ?>
<?php $class = 'col-sm-12'; ?>
<?php } ?>
<div id="content" class="<?php echo $class; ?>"><?php echo $content_top; ?><?php echo $content_bottom; ?></div>
<?php echo $column_right; ?></div>
</div>
<?php echo $footer; ?>
如果没有列左列或右列,如何显示col-sm-12?
提前致谢。
添加了控制器
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Home extends MX_Controller {
public function index() {
$data['column_left'] = Modules::run('catalog/common/column_left/index');
$data['column_right'] = Modules::run('catalog/common/column_right/index');
$data['content_top'] = Modules::run('catalog/common/content_top/index');
$data['content_bottom'] = Modules::run('catalog/common/content_bottom/index');
$data['footer'] = Modules::run('catalog/common/footer/index');
$data['header'] = Modules::run('catalog/common/header/index');
return $this->load->view('theme/default/template/common/home_view', $data);
}
}
答案 0 :(得分:1)
elseif(empty($column_left) || empty($column_right)){ ?>
<?php $class = 'col-sm-12'; ?>
<?php } ?>
答案 1 :(得分:1)
如果设置了$column_left
或$column_right
,那么它将永远不会到达最后else
部分。只需查看!empty()
即可。它将检查值是否为空。
<?php if ($column_left && $column_right) { ?>
<?php $class = 'col-sm-6'; ?>
<?php } elseif (!empty($column_left) || !empty($column_right)) { ?>
<?php $class = 'col-sm-9'; ?>
<?php } else { ?>
<?php $class = 'col-sm-12'; ?>
<?php } ?>
答案 2 :(得分:1)
你不需要把那千个php打开和关闭标签。
<?php
if (!empty($column_left) && !empty($column_right)) {
$class = 'col-sm-6';
} elseif (!empty($column_left) || !empty($column_right)) {
$class = 'col-sm-9';
} else {
$class = 'col-sm-12';
}
?>
<强>已更新强>
从此声明中删除返回
return $this->load->view('theme/default/template/common/home_view', $data);
这应该是:
$this->load->view('theme/default/template/common/home_view', $data);
答案 3 :(得分:1)
我发现什么问题是最简单的事情我忘记了在我的列上左右添加id
感谢@tiGer的删除回复也帮助了
列左侧模块
<?php if ($modules) { ?>
<column id="column-left" class="col-sm-3 hidden-xs">
<?php foreach ($modules as $module) { ?>
<?php echo $module; ?>
<?php } ?>
</column>
<?php } ?>
专栏
<?php if ($modules) { ?>
<column id="column-right" class="col-sm-3 hidden-xs">
<?php foreach ($modules as $module) { ?>
<?php echo $module; ?>
<?php } ?>
</column>
<?php } ?>