KSmarty은 Kohana와 Smarty를 통합하기위한 Kohana 모듈입니다. 내 현재 프로젝트 (이미 Smarty 사용)를 Kohana를 사용하여 마이그레이션하려고합니다.Kohana와 Smarty 3.1 사용하기 3.3
나는 KSmarty를 설정하려고하는데 템플릿을 작동시키는 데 어려움을 겪고 있습니다. 이 KSmarty에서 "Hello World」의 예는 다음과 같습니다
응용 프로그램/클래스/컨트롤러/Welcome.php
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Welcome extends Controller_Template
{
public $template = 'welcome';
public function action_index()
{
// Assign a value to the variable 'intro'
$this->template->intro = 'Hello world!';
// Create a nested view by loading a different template
$this->template->content = View::factory('content');
}
}
// End Welcome
응용 프로그램/뷰/welcome.tpl
<html>
<body>
<h1>{$intro}</h1>
<p>
{$content}
</p>
</body>
</html>
application/views/content.tpl
Yes, this works!
그러나 나를 위해 컨트롤러 /보기 콤보가 예상대로 작동하지 않습니다. 여기에 내가 시도했다 action_index()
의 변종이다 : 나는 단순히 같은 Ksmarty::instance()
를 사용하여 내 웹 사이트 작업을 얻을 수
public function action_index()
{
echo 'foo';
}
// Output: foo
public function action_index()
{
// Assign a value to the variable 'intro'
$this->template->intro = 'Hello world!';
// Create a nested view by loading a different template
$this->template->content = View::factory('content');
}
// No output
// No error in apache log, php log, or kohana log
public function action_index()
{
Ksmarty::instance()->assign(array(
'intro' => 'Hello world!',
'content' => APPPATH.'/views/content.tpl'
// Note: also changed {$content} in template to {include $content}
));
Ksmarty::instance()->display(APPPATH.'/views/welcome.tpl');
}
// Expected HTML output
는, 그러나 이것은 Kohana보기 시스템이 디자인 된 방법이 아니며, 그것은 느낌 특히 KSmarty 예제가 Kohana의 Views 사용과 일치하기 때문에 고르지 마세요.
나는 머리카락을 잡아 당기는 양을 감안할 때 인상적인이 하나를 고정하려고 노력하면서 내 머리카락을 당겨 내고있다. Kohana는 초기 설치시에 나를 주었다. 내가 도대체 뭘 잘못하고있는 겁니까?
아, 나는이 점에 도달하는 KSmarty 두 변경할 수 있습니다 Kohana::$config->load('smarty')
로 대체 Kohana::config('smarty')
의
- 모든 인스턴스를; 내가 알 수있는 한, 이것은 Kohana의 버전 변경 사항입니다.
$s->security = Kohana::$config->load('smarty')->security;
; 내가 알 수있는 한, 이것은 Smarty의 버전 변경 사항이며, KSmarty는FALSE
으로 구성됩니다.