2012-09-11 2 views
0

이것은 간단한보기 템플릿CakePHP - 템플릿보기 - 가져온 내용의 기본값은 무엇입니까?

// app/View/Common/view.ctp 
<h1><?php echo $this->fetch('title'); ?></h1> 
<?php echo $this->fetch('content'); ?> 

<div class="actions"> 
    <h3>Related actions</h3> 
    <ul> 
    <?php echo $this->fetch('sidebar'); ?> 
    </ul> </div> 

의 책의 예제이며,이는이

// app/View/Posts/view.ctp 
<?php 
$this->extend('/Common/view'); 

$this->assign('title', $post); 

내 질문을 확장 할 수있는 방법이다 : 나는 기본값을 설정하는 방법 /내용 (말)을 제목, 필요한 경우 덮어 쓰시겠습니까?

고맙습니다!

답변

1

var. 비어 있지 않으면 echo, 그렇지 않으면 기본값을 echo합니다.

$title = $this->fetch('title'); 
echo !empty($title) ? $title : 'Default'; 
+0

아주 쉽습니다. 나는 짐작 했어야했다. 고맙습니다! – Michael

관련 문제