汗 有helper居然不用。。=.=|||
我认为也是写个helper最好啦
非常清晰
helper写变量也可以吗,不是用来写function的吗:o
helper 其实就是 include 呵呵
能不能把代码简单的写下......
global 变量在哪儿定义?
[ 本帖最后由 097633 于 2009-1-15 15:27 编辑 ]
097633 发表于 2009-1-15 15:08 http://codeigniter.org.cn/forums/images/common/back.gif
如:
function a()
{
global $vars_g ;
$vars_g = "xxxxxxxx";
//.......
}
function b()
{
global $vars_g;
//..........
$result = do_something($vars_g);
return $result;
}
这是php中用全局变量的方法。
Hex 发表于 2009-2-16 22:39 static/image/common/back.gif
helper 其实就是 include 呵呵
请教Hex:是在application/helpers目录下添加一个MY_xx_helper.php文件嘛?然后可以在aotuload.php文件里面配置自动载入?
甲鱼 发表于 2012-5-13 19:06 static/image/common/back.gif
请教Hex:是在application/helpers目录下添加一个MY_xx_helper.php文件嘛?然后可以在aotuload.php文件里 ...
看这里 http://codeigniter.org.cn/user_guide/general/helpers.html
helper 文件中可以调用数据库吗?我意思读取配置数据。这个数据是存在数据库中的表里的。为这问题我浪费好几天了。一直解决不了。。郁闷
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Message
{
/**
* success,error,info,block
*/
public static function set($msg,$type = 'success')
{
$session = &load_class('Session');
/*调用bootstrap alert 样式*/
$msg_code = '<div class="alert alert-'.$type.'"><strong>'.$type.'!</strong>'.$msg.'<a class="close" data-dismiss="alert" href="#">×</a></div>';
$session->set_flashdata('message',$msg_code);
}
}
Hex 发表于 2009-1-15 23:56
还是写个 Helper 吧!
我也觉得,写个helper挺好的,还可以通过helper读取配置文件