• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Better view files

(08-04-2015, 08:32 AM)iamthwee Wrote: Thanks, I think I definitely made an elementary school boy error in rushing the prototype CMS system by writing very poor view files.  

Take a look at the template I use to handle about 4,000 web-pages:

PHP Code:
require VIEWPATH .'_atemplate/incs/__doctype-strict.php';

 require VIEWPATH .'_atemplate/incs/__header.php';
   $css base_url() .VERPATH .'assets/css/lazyYT.css';
   echo NN.'<link rel="stylesheet" href="' .$css .'">';
   echo $tmp = <<< ______TMP
      .grid .item {display: inline-block; 
                   width:47%; min-width:280px; margin: 0 1% 8% 1%; padding:0;}
 echo isset($css2Add) ? $css2Add NULL;


  <div class="logo por tac"> <?php # (isset($HAS_PICTURE) && $HAS_PICTURE) ? 'bg6' : 'bg4'; ?>

    <div class="clr w88 mga">
         # Hunky Dory  
         if(1) require VIEWPATH .'_atemplate/incs/__DS_DEBUG_HEADERS.php'

       require VIEWPATH .'_atemplate/incs/__menu-btns-2015-06-17.php'

       if( isset($HAS_PICTURE) && $HAS_PICTURE ):
         echo '<i class="poa pbr">Has Pictures</i>';
         $tmp 'http://www.google.com/webmasters/tools/mobile-friendly/'
                .'?url=' .$canonical;
           echo '<a class="poa pbr tdn fg6" href="' .$tmp .'">';
             echo 'Google Mobile Friendy';
           echo '</a>';
  </div><?php #logo ?>
       echo '<div class="fll p42">
                <a href="/c_edit"> <b>edit</b> </a>       

 <div id="layout"><!-- Menu toggle -->

   <div id="main">
      <div class="content">
        <div class="header">
          <br />
          <h1 class="ooo tac"> <?= ucwords($joke_title); ?></h1>
          <?php $titleH2 = isset($titleH2) ? $titleH2 '&nbsp;';?>
          <h4 class="ooo tac fg4"> <?=$titleH2;?> <br /><br /> </h4>

           $pix    = array('pix''funny-pix''funny-pictures''health-and-safety'
           $groups = array('top-10-jokes''top-20-jokes''favourites','blondes' 
           $blogs  = array('debug''admin','subscribe','spend_ways'

           $segs   strtolower ($this->uri->segment(1));

           if( isset($jotd) ) {
             require VIEWPATH .'_atemplate/specials/jotd.php';

           }elseif( isset($page_kid) && 'v-001/login' === $page_kid ) {
             require VIEWPATH .'_atemplate/specials/login.php';

           }elseif( in_array($segs, ['joke-of-the-day''calendar']) ) {
             require VIEWPATH .'_atemplate/specials/joke-of-the-day-calendar.php';

           }elseif( 'c_tabs'===$theClass ) {
             require VIEWPATH .'_atemplate/tabs/' .$segs .'.php';

           }elseif( strpos($canonical'all-the-jokes') ) {
             require VIEWPATH .'_atemplate/specials/all-the-jokes.php';

           }elseif( in_array($segs, ['eliza']) ) {
             require VIEWPATH .'_atemplate/specials/eliza.php';

           }elseif( in_array($segs, ['the-frogs']) ) {
             require VIEWPATH .'_atemplate/specials/the-frog.php';

           }elseif( isset($amjuggle) ) {
             require VIEWPATH .'_atemplate/specials/amjuggle.php';

           }elseif( isset($thepix) ) {
             require VIEWPATH .'_atemplate/specials/pix.php';

           }elseif( isset($thelot) ) {
             require VIEWPATH .'_atemplate/specials/thelot.php';

           }elseif( isset($vids) ) {
             require VIEWPATH .'videos/video-001.php';

           }/* ALWAYS SET */ elseif( isset($joke_memo) ) {
             require VIEWPATH .'_atemplate/specials/joke-memo-string.php';

           }elseif( 'videos'===$segs ) {
             echo '<h3 class="tac">Coming Back Soon</h3>';

           }else {
             echo 'Problem ?'

      </div><?php # content ?>
    </div><?php # main ?>
  </div><?php # layout ?>

  <?php /* if(0): ?>
    <div class="tac ba_468x60">
      < ?php # require VERPATH .'assets/js/propellerads-banner-468x60.js';? >
  <?php endif; */ 

( isset($quotes) && ('jotd' !== $this->uri->segment(1)) ):
     #echo '<hr />';
     echo '<div class="clb w88 mga tac">';
       echo '<dl class="dib tal p42 bd2 bdr bg1">';
         echo '<dt class="fs2"><strong>
                Quotes for Today:
         foreach($quotes as $quote)
           echo '<dd><br />'.$quote .'</dd>';
       echo '</dl>';
     echo '</div><br />';

  <div id="XXXfoot" class="bg5 fg4 tac">
    <?php require VIEWPATH .'_atemplate/incs/__footer.php';?>

   #if(! $_SESSION['jjj']['profiler']): 
     # echo '</body></html>'; 

echo '</body></html>'

Hmm, yeah I certainly don't want to echo out html using php Wink but thanks...

I started a simple test with the html parser.

PHP Code:
class Template_test extends CI_Controller {

    public function 
$query $this->db->get();

$url1 site_url('admin/template_test');

$data = array(
'url1'         => $url1,
'page_title'   => 'My Page Title',
'page_heading' => 'My Page Heading',
'pages' => $query->result_array()


And more view files looks a lot better:

<div class="pmf-container" >
    <div class="row pad" >
        <div class="col-sm-12">
            <header class="panel-heading font-bold">{page_title}</header>
            <section class="panel">
                <div class="panel-body">


Like we discussed before I don't think there should be a great deal of logic in your views other than for loops and some simple if else statements. I like the idea of passing these vars to the view in a multi-dimensional array. Even removing the site_url() from the view and setting this as a one word variable and passing it to the view seems better. I'm also going to get rid of all the codeigniter form_helpers in the view, well most of them.
Practical guide to IgnitedCMS - Book coming soon

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.