Codeigniter에서 smarty와 adodb를 통합하는 방법에 대한 분석

不言
풀어 주다: 2023-04-01 08:12:01
원래의
1608명이 탐색했습니다.

본 글은 코드이그나이터에서 스마티와 adodb를 통합하는 방법을 주로 소개하고, 코드이그나이터 라이브러리의 사용법을 예시로 분석해 도움이 필요한 친구들이 참고할 수 있습니다

이 글의 예에서는 스마티를 통합하는 방법이 설명되어 있습니다. Codeigniter의 adodb. 참조를 위해 모든 사람과 공유하세요. 세부 사항은 다음과 같습니다:

CodeIgniter에서 자신만의 라이브러리를 작성하려면 두 개의 파일을 작성해야 합니다. 하나는 application/init 아래의 init_myclass.php 파일입니다(init 디렉토리가 없는 경우, 직접 만들어 보세요). 다른 하나는 application/libraries 디렉토리에 myclass.php 파일을 생성하는 것입니다.

여기서 myclass는 수업 이름입니다. 여기서는 몇 가지 규칙에 대한 설명서를 읽어보시면 됩니다.

1) application/libraries에 각각 mysmarty.php와 adodb.php를 생성합니다
mysmarty.php 파일 내용은 다음과 같습니다.

<?php
// load Smarty library
require(&#39;Smarty/Smarty.class.php&#39;);
// The setup.php file is a good place to load
// required application library files, and you
// can do that right here. An example:
// require(&#39;guestbook/guestbook.lib.php&#39;);
class MySmarty extends Smarty {
 function MySmarty()
 {
    // Class Constructor.
    // These automatically get set with each new instance.
    $this->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(&#39;app_name&#39;, &#39;Guest Book&#39;);
 }
}
?>
로그인 후 복사

파일 경로는 상황에 따라 수정됩니다. 경로는 현재 파일의 현재 디렉토리가 아닌 현재 파일의 홈 디렉토리에서 시작하는 상대 경로입니다. 예를 들어, 위의 require('Smarty/Smarty.class.php')는 응용 프로그램에 상대적이지 않습니다. /libraries 디렉토리이지만 $_SERVER['DOCUMENT_ROOT'] 디렉토리에 상대적입니다.

adodb.php 파일의 내용은 다음과 같습니다.

<?php if (!defined(&#39;BASEPATH&#39;)) exit(&#39;No direct script access allowed&#39;);
class Adodb
{
  function Adodb()
  {
    //$dsn="dbdriver://username:password@server/database"
    $dsn = &#39;mysql://user:password@localhost/xxxx&#39;;
    require_once("adodb/adodb.inc".EXT);
    $this->adodb =& ADONewConnection($dsn);
    $this->adodb->Execute("set NAMES &#39;utf8&#39;"); 
  }
}
?>
로그인 후 복사

2) application/init 디렉토리에 init_adodb.php와 init_mysmarty.php를 각각 생성합니다.

init_adodb.php 파일 내용은 다음과 같습니다.

<?php if (!defined(&#39;BASEPATH&#39;)) exit(&#39;No direct script access allowed&#39;);
$obj =& get_instance();
$obj->adodb = new Adodb($obj);
$obj->ci_is_loaded[] = &#39;adodb&#39;;
로그인 후 복사

init_mysmarty.php 파일 내용은 다음과 같습니다.

<?php if (!defined(&#39;BASEPATH&#39;)) exit(&#39;No direct script access allowed&#39;);
if ( ! class_exists(&#39;MySmarty&#39;))
{
  require_once(APPPATH.&#39;libraries/mysmarty&#39;.EXT);
}
$obj =& get_instance();
$obj->mysmarty = new MySmarty();
$obj->ci_is_loaded[] = &#39;mysmarty&#39;;
?>
로그인 후 복사

3) 이를 사용합니다.
application/controllers 디렉터리에 필요한 파일을 만듭니다. , you can adodb와 smarty를 사용하는 방법입니다.

<?php
class Test extends Controller {
 function Test()
 {
  parent::Controller(); 
  $this->load->library(&#39;mysmarty&#39;);
  $this->load->library(&#39;adodb&#39;);
 }
 function index()
 {
 $this->load->library(&#39;adodb&#39;);
 $row = $this->adodb->adodb->getrow(&#39;SELECT * FROM admin&#39;);
    $this->mysmarty->assign("row",$row);
    $this->mysmarty->display("test.tpl");
 }
}
?>
로그인 후 복사

여기서 adodb가 왜 두 번 필요한지 모르겠습니다. 공식적인 방법에 따르면 한 번만 필요하지만 그의 방법은 제게는 잘못되었습니다. 아직 CodeIgniter에 대해 잘 모르기 때문일 수도 있습니다. 더 깊이 파고들면 해결책이 있는지 알 수 있을 것입니다. 그러나 적어도 이것은 현재로서는 작동합니다.

위 내용은 이 글의 전체 내용입니다. 모든 분들의 학습에 도움이 되었으면 좋겠습니다. 더 많은 관련 내용은 PHP 중국어 홈페이지를 주목해주세요!

관련 권장 사항:

PHP Symfony 및 CodeIgniter 프레임워크의 Nginx 재작성 규칙 구성 정보

CI 프레임워크의 $this->load->library() 사용 분석 정보

위 내용은 Codeigniter에서 smarty와 adodb를 통합하는 방법에 대한 분석의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!