fjctlzy 发表于 2009-5-9 23:44:53

如何在ci里面写一个alert函数

function alert($msg){
      echo "<script language=\"javascript\" type=\"application/javascript\">alert($msg);</script>";
    }
我写成这样,使用的时候提示
A PHP Error was encounteredSeverity: Warning
Message: Cannot modify header information - headers already sent by(output started atE:\xampp\htdocs\securities\system\application\libraries\functions.php:77)
Filename: helpers/url_helper.php
Line Number: 541

Hex 发表于 2009-5-10 00:53:16

搞不懂楼主想干什么,错误信息和楼主的问题毫不相关。
如果要在 CI 中使用一个单独的函数,请使用 helper。

http://codeigniter.org.cn/user_guide/general/helpers.html

darklord 发表于 2009-5-10 08:38:51

echo 又见echo 你一天到晚的echo 用框架干嘛

fjctlzy 发表于 2009-5-11 08:48:04

不就是尝试一下嘛 。。。

fjctlzy 发表于 2009-5-11 08:55:59

就是我想写一个提示错误信息的函数怎么写。。。

fjctlzy 发表于 2009-5-11 08:56:16

js里面不是有个alert函数吗,我想借用过来。

yuwen002 发表于 2009-5-11 09:18:49

简单的东西写成函数。
复杂的东西就写成类吧。(扩展性好)
看看帮助中的插件。还有创建类库。
CI中自己的东西越多。开发的速度越快

Hex 发表于 2009-5-11 10:01:24

楼主不要把 js 和 php 搞混。
在 CI 提示错误信息也要用视图,我回答够清楚了吧?呵呵

soho7 发表于 2009-8-6 09:56:43

楼主是不是想这样啊
<?php
........
?>
    <script>
      alert(".....");
    </script>
<?php
.............
?>

yinzhili 发表于 2009-8-6 12:13:48

本帖最后由 yinzhili 于 2009-8-6 12:15 编辑

可以这么写:

echo "<script language='JavaScript'>alert('这是提示信息!');</script>";

这样就可以弹出一个JS警告框了。
页: [1]
查看完整版本: 如何在ci里面写一个alert函数