2012-12-08 3 views
0

CakePHP에서 $this->set() 메서드를 사용하여 자신의 함수를 어떻게 사용하고 정의 할 수 있을지 궁금한가요? 나는 ...

AppController.php

<?php 
    function checkSetup() { 
     if ($this->Auth->user('setup') == 'notcomplete') { return true; } 
    } 

    $this->set('isSetup', checkSetup()); 
?> 

을 이런 식으로 뭔가를하고 싶지 그리고 난에 액세스 할 수 내보기 파일을 호출합니다 :

<?php if ($isSetup): ?> 
You haven't setup your profile yet! 
<?php endif; ?> 

I 시도해 봤지만 심각한 치명적인 오류가 발생하는 것처럼 명확하게 작동하지 않습니다. 내가 어떻게이 일을 할 수 있는지에 대한 아이디어 나 제안?

답변

1
$this->set('isSetup', checkSetup()); 

해당 라인은 호출하기 위해 일부 기능 안에 있어야합니다. 아마도 앱 컨트롤러의 beforFilter에서 원하는 -이 같은 : 당신의 도움에 대한

<?php 

App::uses('Controller', 'Controller'); 

class AppController extends Controller { 

    function beforeFilter() { 
     $this->set('isSetup', checkSetup()); 
    } 

    function checkSetup() { 
     if ($this->Auth->user('setup') == 'notcomplete') { return true; } 
    } 

} 

?> 
+0

감사합니다, 나는 그것을 함수에 있어야했다 몰랐어요. 힘내 친구 야 ;) –