我有一个显示项目字段视图的页面。这是我要完成的工作:如果表数据为空(例如,表单中没有输入城市的数据),那么我想隐藏字段和字段名称/标签。如此处所示:
因此,Notes、City 和 Branch 字段不应显示。我怎样才能做到这一点?
这是我的视图页面代码:
<div class="projects view">
<h2><?php echo __('Project'); ?>: <small><?php echo h($project['Project']['title']); ?></small></h2>
<div class="well">
<dl>
<dt><?php echo __('Name'); ?></dt>
<dd>
<?php echo h($project['Project']['title']); ?>
</dd>
<dt><?php echo __('Url'); ?></dt>
<dd>
<?php echo h($project['Project']['slug']); ?>
</dd>
<dt><?php echo __('Notes'); ?></dt>
<dd>
<?php echo h($project['Project']['description']); ?>
</dd>
<dt><?php echo __('Branch'); ?></dt>
<dd>
<?php echo h($project['Project']['test']); ?>
</dd>
<dt><?php echo __('Type of Work'); ?></dt>
<dd>
<?php echo h($project['Project']['type']); ?>
</dd>
<dt><?php echo __('Street Address'); ?></dt>
<dd>
<?php echo h($project['Project']['street_address']); ?>
</dd>
<dt><?php echo __('City'); ?></dt>
<dd>
<?php echo h($project['Project']['city']); ?>
</dd>
<dt><?php echo __('State'); ?></dt>
<dd>
<?php echo h($project['Project']['state']); ?>
</dd>
<dt><?php echo __('Supervisor'); ?></dt>
<dd>
<?php echo h($project['Project']['supervisor']); ?>
</dd>
<dt><?php echo __('Supervisor Phone'); ?></dt>
<dd>
<?php echo h($project['Project']['supervisor_phone']); ?>
</dd>
<dt><?php echo __('# of Workers Needed'); ?></dt>
<dd>
<?php echo h($project['Project']['workers']); ?>
</dd>
<dt><?php echo __('Hotel Name'); ?></dt>
<dd>
<?php echo h($project['Project']['hotel_name']); ?>
</dd>
<dt><?php echo __('Hotel Address'); ?></dt>
<dd>
<?php echo h($project['Project']['hotel_address']); ?>
</dd>
<dt><?php echo __('Hotel City'); ?></dt>
<dd>
<?php echo h($project['Project']['hotel_city']); ?>
</dd>
<dt><?php echo __('Hotel State'); ?></dt>
<dd>
<?php echo h($project['Project']['hotel_state']); ?>
</dd>
<dt><?php echo __('Hotel Phone'); ?></dt>
<dd>
<?php echo h($project['Project']['hotel_number']); ?>
</dd>
<dt><?php echo __('Total # of Rooms'); ?></dt>
<dd>
<?php echo h($project['Project']['room_number']); ?>
</dd>
<dt><?php echo __('Hotel Notes'); ?></dt>
<dd>
<?php echo h($project['Project']['hotel_notes']); ?>
</dd>
<dt><?php echo __('PPE'); ?></dt>
<dd>
<?php echo h($project['Project']['ppe']); ?>
</dd>
<dt><?php echo __('Phases'); ?></dt>
<dd>
<?php echo h($project['Project']['phase_count']); ?>
</dd>
<dt><?php echo __('% Completed'); ?></dt>
<dd>
<?php echo h($project['Project']['percent_completed']); ?>%
</dd>
<dt><?php echo __('Start Date'); ?></dt>
<dd>
<?php echo $this->Layout->displayProjectDates($project['Project']['date_start']); ?>
</dd>
<dt><?php echo __('End Date'); ?></dt>
<dd>
<?php echo $this->Layout->displayProjectDates($project['Project']['date_end']); ?>
</dd>
<dt><?php echo __('Project Duration'); ?></dt>
<dd>
<?php echo $this->Time->dateDiffDays($project['Project']['date_start'], $project['Project']['date_end']); ?>
</dd>
<dt><?php echo __('Archived'); ?></dt>
<dd>
<?php echo $this->Layout->boolYesNo($project['Project']['archived']); ?>
</dd>
<dt><?php echo __('Created'); ?></dt>
<dd>
<?php echo $this->Layout->displayTimeDefault($project['Project']['created']); ?>
</dd>
<dt><?php echo __('Modified'); ?></dt>
<dd>
<?php echo $this->Layout->displayTimeDefault($project['Project']['modified']); ?>
</dd>
</dl>
</div>
现在我假设代码看起来像这样?:
<?php if (!empty($project['Project']['city'])) { } ?>
我仍在学习 PHP,经验不足,因此将不胜感激!如果您需要查看我的控制器以获得更好的想法,请告诉我。
谢谢!