开发者

How to apply a variable filter to this model?

I have this view how do I only iterate this unit model when the $wprice is > 1

<?php  
 $model->getFeaturedVehicles(10, 0, unserialize($vtype), unserialize($makes), $p1range, $p2range, $filters) ?>

    <div id="adspecials"><?php while ($unit = $model->iterate()): ?>
  <div class="adwrappe开发者_C百科r">
    <div class="ad">
        <h1 class="cufon"><?php echo $unit->wprice,'</h1><h4>Preferred Club Pricing</h4>' ?>
      </div>
    </div>
  </div><?php endwhile; ?>
</div>


From your view it seems like wprice is a property of $unit, so you should just be able to add an additional if-statement within the while-loop:

<?php  
 $model->getFeaturedVehicles(10, 0, unserialize($vtype), unserialize($makes), $p1range, $p2range, $filters) ?>

<div id="adspecials">
<?php while ($unit = $model->iterate()): 
  if($unit->wprice > 1) :
?>
  <div class="adwrapper">
    <div class="ad">
      <div class="image"> <a href="<?php echo DIR_REL,'/inventory/',$unit->url ?>"><br />
      <h4>View More Information</h4>
       </a> 
      </div>
      <div class="info">
        <h3 class="cufon"><?php echo $unit->description ?></h3>
        <h1 class="cufon">
          <?php echo $unit->wprice,'</h1><h4>Preferred Club Pricing</h4>' ?>
        <p><?php echo $unit->subtitle ?></p>
      </div>
    </div>
  </div>
<?php 
  endif;
endwhile; ?>
</div>

You should also:

  • Validate your HTML (it is not allowed to wrap a link around headers)
  • Check if you can't re-arrange the echo $unit->wprice, '[long string with html]'-statement, it is very hard to read.


How exactly you'd filter your data depends a lot on your model. It looks like your getFeaturedVehicles already takes a filters parameter, so you can likely just add your filter to that collection. Since that looks specific to your code base, we can't really help you with how you'd do that.

If you aren't able to filter the data at the model level, you could just add an if statement to your PHP to just filter out what's displayed. For example:

<?php $model->getFeaturedVehicles(10, 0, unserialize($vtype), unserialize($makes), $p1range, $p2range, $filters) ?>
  <div id="adspecials">
    <?php while ($unit = $model->iterate()): ?>        
      <?php if ($unit->wprice > 1): ?>
        <div class="adwrapper">
          <div class="ad">
            <div class="image">
              <a href="<?php echo DIR_REL,'/inventory/',$unit->url ?>">
                <br />
                <h4>View More Information</h4>
              </a> 
            </div>
           <div class="info">
             <h3 class="cufon"><?php echo $unit->description ?></h3>
             <h1 class="cufon"><?php echo $unit->wprice ?></h1>
             <h4>Preferred Club Pricing</h4>
             <p><?php echo $unit->subtitle ?></p>
           </div>
         </div>
       </div>          
      <?php endif; ?>
    <?php endwhile; ?>
  </div>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜