whosheng 发表于 2012-6-9 17:04:07

CI中html辅助函数img()的灵活运用


   <?php $image_properties = array(
          'src' => 'images/picture.jpg',
          'alt' => 'Me, demonstrating how to eat 4 slices of pizza at one time',
          'class' => 'post_images',
          'width' => '200',
          'height' => '200',
          'title' => 'That was quite a night',
          'rel' => 'lightbox',
);?>
<?php echo img($image_properties);?>
怎样把上面的那个数组定义到其他的层中,而不是都在在V层中写,这样显得视图代码好混乱。在V层中怎么使用?求大家的帮助

貝殼 发表于 2012-6-9 19:08:48

基本不用HTML、表格輔助函數,還是自己來吧!

跳墙的狗 发表于 2012-6-9 19:48:48

用作参数传来传去就可以了

ubuntu 发表于 2012-6-9 21:53:09

在控制器作为变量传过去就行了:)

sdink 发表于 2012-6-10 00:52:42

function img($ay) {
                $rt = '';
                foreach ( $ay as $k => $v ) {
                        $rt = $k . '="' . $v . '"';
                }
                return '<img ' . $rt . '/>';
        }


加个help ,然后这样不行吗?

Hex 发表于 2012-6-10 02:00:55

直接用html是最好的方法

来自:CodeIgniter 中国开发者社区 iPhone客户端

whosheng 发表于 2012-6-10 09:29:07

ubuntu 发表于 2012-6-9 21:53 static/image/common/back.gif
在控制器作为变量传过去就行了:)

这样是可以做,但是我想传的是整个的数组,而不是单个的变量。谢谢你的帮助

ubuntu 发表于 2012-6-10 22:43:02

whosheng 发表于 2012-6-10 09:29 static/image/common/back.gif
这样是可以做,但是我想传的是整个的数组,而不是单个的变量。谢谢你的帮助 ...

。。。你把数组丢到变量里面不就完了吗?什么单个变量双个变量。。。
页: [1]
查看完整版本: CI中html辅助函数img()的灵活运用