codeigniter避免使用html div

rab*_*ne9 0 php syntax html-helper codeigniter

是否有正确的语法来避免codeigniter中的div?我不喜欢一直打开和关闭标签......

<div class="theForm">
    <?php
           echo form_open('edit/links');//this form uploads
           echo "Enter the Name:  ". form_input('name','name');
           echo "Enter the Link:  ". form_input('url','url');
           echo " ".form_submit('submit', 'Submit');
           echo form_close();

if (isset($linksQuery) && count($linksQuery)){
           foreach($linksQuery as $link){
            echo anchor($link['link'],  $link['name'].".",  array("class" => "links"));
            echo form_open('edit/links',array('class' => 'deleteForm'));
            echo form_hidden('name',$link['name']);
            echo " ".form_submit('delete','Delete');
            echo form_close();

            echo br(2);
           }
}
    ?>



  </div>
Run Code Online (Sandbox Code Playgroud)

小智 6

你可以像这样写一个小帮手:

<?php

function div_open($class = NULL, $id = NULL)
{
    $code   = '<div ';
    $code   .= ( $class != NULL )   ? 'class="'. $class .'" '   : '';
    $code   .= ( $id != NULL )      ? 'id="'. $id .'" '         : '';
    $code   .= '>';
    return $code;
}

function div_close()
{
    return '</div>';
}

echo div_open('some_class', 'some_id');
echo 'some content...';
echo div_close();

?>
Run Code Online (Sandbox Code Playgroud)

将产生:

<div class="some_class" id="some_id" >some content...</div>
Run Code Online (Sandbox Code Playgroud)