• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Codeigniter中集成smarty和adodb的方法_php实例

php 搞代码 4年前 (2022-01-25) 20次浏览 已收录 0个评论

本文实例讲述了Codeigniter中集成smarty和adodb的方法。分享给大家供大家参考,具体如下:

在CodeIgniter中要写自己的库,就需要写两个文件,一个是在application/init下面的init_myclass.php文件(如果没有init目录,自己创建)。另外一个就是在application/libraries目录下创建myclass.php文件。

这里myclass是你的类名。一些规则大家看手册就好了,我这里直接就说步骤了。

1)在application/libraries下分别创建mysmarty.php和adodb.php
mysmarty.php文件的内容如下:

Smarty();    $basedir=dirname(__FILE__);    $this->template_dir = "$basedir/templates/";    $this->compile_dir = "$basedir/templates_c/";    $this->config_dir  = "$basedir/configs/";    $this->cache_dir  = "$basedir/cache/";    //$this->compile_check = true;    //this is handy for development and debugging;never be used in a production environment.    //$smarty->force_compile=true;    $this->debugging = false;    $this->cache_lifetime=30;    $this->caching = 0; // lifetime is per cache    //$this->assign('app_name', 'Guest Book'); }}?>

文件路径根据具体情况修改,文件的的路径是相对你的网站的主目录开始的,而不是当前文件的当前目录,比如上面的require(‘Smarty/Smarty.class.php’);不是相对application/libraries目录,而是相对$_SERVER[‘DOCUMENT_ROOT’]目录。

adodb.php文件的内容如下:

adodb =& <i style="color:transparent">本#文来源gaodai$ma#com搞$$代**码网$</i><button>搞代gaodaima码</button>ADONewConnection($dsn);    $this->adodb->Execute("set NAMES 'utf8'");   }}?>

2)在application/init目录下分别创建init_adodb.php和init_mysmarty.php。

init_adodb.php文件内容如下:

adodb = new Adodb($obj);$obj->ci_is_loaded[] = 'adodb';

init_mysmarty.php文件内容如下:

mysmarty = new MySmarty();$obj->ci_is_loaded[] = 'mysmarty';?>

3)使用他们
在application/controllers目录下创建一个你需要的文件,你可以这样来使用adodb和smarty。

load->library('mysmarty');  $this->load->library('adodb'); } function index() { $this->load->library('adodb'); $row = $this->adodb->adodb->getrow('SELECT * FROM admin');    $this->mysmarty->assign("row",$row);    $this->mysmarty->display("test.tpl"); }}?>

我也不知道这里为什么需要两次adodb,按照官方的做法应该只需要一次,但是他的方法在我这里有错误。可能是我对CodeIgniter还不太了解吧,等深入一些,再看看有没有解决办法。不过至少目前这个可以工作了。

希望本文所述对大家PHP程序设计有所帮助。


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Codeigniter中集成smarty和adodb的方法_php实例

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址