2010-01-29 5 views
2

객체를 smarty 태그로 전달할 때 문제가 있습니다.PHP 객체를 멋지게 전달

$contact = new Contacts; 
$smarty = new Smarty; 
$smarty->assign('contact',$contact); 

test.htpl에서 :

<html> 
<head> 
    <title>{$title}</title> 
</head> 
<body> 
    id: {$contact->id} <br/> 
    name: {$contact->name} <br/> 
    email: {$contact->email} <br/> 
    phone: {$contact->phone} <br/> 
</body> 
</html> 

이 잘못된 문자의 경고 '>'로 연결 나는 다음과 같은 코드가 있습니다. 이 문제를 어떻게 해결할 수 있습니까? '이 방법은 다음 또한 다음 돈

<html> 
<head> 
    <title>{$title}</title> 
</head> 
<body> 
    id: {$contact->id} <br/> 
    name: {$contact->name} <br/> 
    email: {$contact->email} <br/> 
    phone: {$contact->phone} <br/> 
</body> 
</html> 

를 작동해야 그것을 호출

$smarty->register_object('contact',$contact); 

를 작동해야 다음을 수행하여

class Contacts 
{ 
public $id = 1; 
public $name = 'Mada'; 
public $email = '[email protected]'; 
public $phone = 123456; 
} 
+0

연락처 수업에 우리에게 무엇을 보여줄 수 있습니까? – RJD22

+0

"현명한 템플릿 개체"를 검색하면 http://www.smarty.net/manual/en/advanced.features.php가 첫 번째 결과로 이어집니다. – zneak

답변

0

:

나는 테스트를 위해이 클래스를 사용 이 메소드를 호출해야합니다.

$smarty->assign('contact',$contact); 
1

사용하는 것은

$smarty->assign_by_ref('contact',$contact); 

이것은 당신이 기대하는 방법으로 액세스 할 수 있습니다.

register_object()를 사용하는 것도 옵션이며 템플릿에서 사용할 수있는 것을 제한 할 수 있지만 다른 템플릿 형식 (초기 $ 없음)을 의미합니다.

관련 문제