|
楼主今天比较懒,所以突发奇想仿照form helper函数做了一个div函数。
一直试验了一个小时 发现按照手册上所写的 MY_div_helper.php一直在报错,后来实在不行改成了 MY_form_helper.php。无报错
接下来直接在视图文件中使用
PHP复制代码
<style type="text/css"> .fu {width:300px;margin:60px;}</style>
<?php $nong = array ( 'class' => 'fu', );?>
<?php div_open ($nong);?>
test
<?php div_close (); ?> 复制代码
完全没效果,查看网页源代码没有div。
MY_form_helper.php代码如下
PHP复制代码 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
if ( ! function_exists('div_open')){
function div_open ($attributes = array()){
$CI =& get_instance ();
$div = '<div " "';
$div .= _atts_to_string ($attributes);
$div .= '>';
return $div;
}
}
if ( ! function_exists('div_close')){
function div_close () {
return "</div>";
}
}
if (!function_exists('_atts_to_string'))
{
function _atts_to_string ($attributes)
{
if (is_array($attributes) AND count($attributes) > 0)
{
$atts = '';
foreach ($attributes as $key => $val)
{
$atts .= ' '.$key.'="'.$val.'"';
}
return $atts;
}
}
}
复制代码
|
|