CodeIgniter를 사용하여 Smarty를 통합하는 방법

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

이 글은 주로 CodeIgniter가 Smarty를 통합하는 방법을 소개하고, Smarty3.1.27을 통합하는 CodeIgniter3.0.3의 단계와 관련 설정 기술을 예제 형식으로 분석합니다. 필요한 친구들이 참고할 수 있습니다

이 글의 예시는 CodeIgniter의 Smarty 통합 방식. 참고할 수 있도록 모든 사람과 공유하세요. 세부 사항은 다음과 같습니다.

CI3.0.2가 출시된 후에도 템플릿 클래스는 여전히 사용하기 쉽지 않고 컴파일할 수도 없다고 생각합니다. Smarty는 강력한 기능을 가지고 있습니다. 일단 익숙해지면 포기하기가 어렵습니다. 게다가 파일을 빠르게 컴파일하고 실행할 수 있어 CI의 부족한 템플릿 기능을 보완할 수 있습니다. CI 버전 3.0.3과 Smarty 버전 3.1.27을 통합하고 있습니다. 통합 프로세스는 아래에 설명되어 있습니다.

1. smarty-3.1.27

2. CI 프로젝트의 애플리케이션 라이브러리에 smarty-3.1.27의 압축을 풀고 다른 파일을 삭제합니다.

3. applicationlibraries 디렉터리에 Ci_smarty.php 파일을 만듭니다. 코드는 다음과 같습니다.

if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require(APPPATH.'libraries/smarty-3.1.27/libs/Smarty.class.php');
class Ci_smarty extends Smarty {
 protected $ci;
 public function __construct()
 {
 parent::__construct();
 $this->ci = & get_instance();
 $this->ci->load->config('smarty');//加载smarty的配置文件
 $this->cache_lifetime =$this->ci->config->item('cache_lifetime');
 $this->caching = $this->ci->config->item('caching');
 $this->config_dir = $this->ci->config->item('config_dir');
 $this->template_dir = $this->ci->config->item('template_dir');
 $this->compile_dir = $this->ci->config->item('compile_dir');
 $this->cache_dir = $this->ci->config->item('cache_dir');
 $this->use_sub_dirs = $this->ci->config->item('use_sub_dirs');
 $this->left_delimiter = $this->ci->config->item('left_delimiter');
 $this->right_delimiter = $this->ci->config->item('right_delimiter');
 }
}
로그인 후 복사

4. applicationconfig 디렉터리에 smarty.php 구성 파일을 만듭니다. 코드는 다음과 같습니다.

if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$config['cache_lifetime'] = 60;
$config['caching'] = false;
$config['template_dir'] = APPPATH .'views';
$config['compile_dir'] = APPPATH .'views/template_c';
$config['cache_dir'] = APPPATH . 'views/cache';
$config['config_dir'] = APPPATH . 'views/config';
$config['use_sub_dirs'] = false; //子目录变量(是否在缓存文件夹中生成子目录)
$config['left_delimiter'] = '{';
$config['right_delimiter'] = '}';
로그인 후 복사

5. applicationcore의 MY_controller.php 코드는 다음과 같습니다.

class MY_controller extends CI_Controller {
 public function __construct() {
 parent::__construct();
 }
 public function assign($key,$val)
 {
 $this->ci_smarty->assign($key,$val);
 }
 public function display($html)
 {
 $this->ci_smarty->display($html);
 }
}
로그인 후 복사

이제 구성 통합 작업은 끝났습니다. 이제 구성이 성공했는지 확인해야 합니다.

7. applicationcontrollers의 Welcome.php를 수정합니다. 코드는 다음과 같습니다:

defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends MY_controller {
 public function index()
 {
 $test='ci 3.0.3 + smarty 3.1.27 配置成功';
 $this->assign('test',$test);
 $this->display('test.html');
 }
}
로그인 후 복사

그런 다음 applicationviews 아래에 test.html 파일을 만듭니다. 코드는 다음과 같습니다.

{$test}
로그인 후 복사

브라우저 주소 표시줄에 입력: http ://localhost/index .php/Welcome

결과는 다음과 같습니다:

ci 3.0.3 + smarty 3.1.27 配置成功
로그인 후 복사

완료!

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

관련 권장 사항:

Codeigniter에서 smarty와 adodb를 통합하는 방법 분석 정보

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

위 내용은 CodeIgniter를 사용하여 Smarty를 통합하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

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