2017-11-10 4 views
0

나는 이것을 다른 사람과 결합하고 싶습니다. 어떤 아이디어? 나는 PHP를 처음 사용합니다. $ perms가 FALSE 인 것에 따라 입력을 변경하도록하고 싶습니다.다른 PHP가 작동하지 않는 경우 간단한 PHP

<? if ($perms['user_profiles|edit_billable']===TRUE) { ?> 
    <div class="field"> 
     <label><?=l(273)?></label> 
     <div class="input"> 
       <input type="checkbox" name="billable" value="1" data-bind="checked: userProfile().billable, disable:isBillable();"> 
     </div> 
     </div> 
    </div> 
<? } ?> 

    <? if ($perms['user_profiles|edit_billable']===FALSE) { ?> 
    <div class="field"> 
     <label><?=l(273)?></label> 
     <div class="input"> 
    <!-- This is where the else would go -->  
       <input type="checkbox" name="billable" value="1" data-bind="checked: userProfile().billable, enable:isBillable();"> 
     </div> 
     </div> 
    </div> 
<? } ?> 
+3

짧은 태그 사용? 오류를 확인 했습니까? –

+1

어떤 일이 일어나고 * 기대 * 할 일을 추가 할 수 있습니까? – jbehrens94

+0

오류 로그를 게시 할 수 있습니까? –

답변

0

간단한 구문을 사용해 보셨습니까?

<?php if ($perms['user_profiles|edit_billable']): ?> 
     <div class="field"> 
     <label><?=l(273)?></label> 
     <div class="input"> 
       <input type="checkbox" name="billable" value="1" data-bind="checked: userProfile().billable, disable:isBillable();"> 
     </div> 
     </div> 
    </div 
<?php else: ?> 
     <div class="field"> 
     <label><?=l(273)?></label> 
     <div class="input"> 
    <!-- This is where the else would go -->  
       <input type="checkbox" name="billable" value="1" data-bind="checked: userProfile().billable, enable:isBillable();"> 
     </div> 
     </div> 
    </div> 
<?php endif; ?> 

아마, 당신이 정말 당신의 문제를 해결할 수없는 경우뿐만 아니라 당신의 php.ini에 우리가 그 오류 로그를 얻을 때까지

short_open_tag=On 
+4

대답입니까? 또는 추측? –

+0

다른 구문을 제안하는 이유는 무엇입니까? 문제는 if와 else가 작동하지 않는다는 것을 나타내며, PHP에서는 작동해야합니다. 이것은 그의 문제에 대한 해결책이 아닙니다. – Glubus

1

, 우리는 알 수 없습니다를 그 구문을 사용하도록 설정해야하지만,의 것 최소한 우리는 3 진을 사용하고 변경된 섹션만을 출력함으로써 코드를 상당히 작게 만들 수 있습니다.

<? $data-bind = $perms['user_profiles|edit_billable'] ? "checked: userProfile().billable, enable:isBillable();" : "checked: userProfile().billable, disable:isBillable();" ?> 
<div class="field"> 
    <label><?=l(273)?></label> 
    <div class="input"> 
     <input type="checkbox" name="billable" value="1" data-bind="<?=$data-bind?>"> 
    </div> 
</div> 

또한 나는 그 태그에 대한 지원을 해제 할 수 있기 때문에 <?처럼,이 코드는 휴대용 및 다른 사람에 의해 사용하려는 경우 권장하지 않습니다, 짧은 태그를 사용하여 언급하겠습니다. 대신 다음과 같은 형식 :

<?php $data-bind = $perms['user_profiles|edit_billable'] ? "checked: userProfile().billable, enable:isBillable();" : "checked: userProfile().billable, disable:isBillable();" ?> 
<div class="field"> 
    <label><?php echo l(273)?></label> 
    <div class="input"> 
     <input type="checkbox" name="billable" value="1" data-bind="<?php echo $data-bind?>"> 
    </div> 
</div> 

더 많은 사람이 더 많은 수의 사람이 실행할 수 있습니다. 다른

+0

게시 이유는 무엇입니까? 이것은 문제와 관련이 없습니다. 사람들은 이것을이 문제에 대한 해결책으로 잘못 생각할 수 있으며 그로 인해 시간을 낭비 할 수 있습니다. – Glubus

+0

이것은 문제의 해결책입니까? OP는 더 나은 논리를 사용하기 위해 코드를 페어링하는 방법을 물었고, 설정 한 것처럼 삼중 항이 바로 그 것이다. 이걸 정말로 이해하지 못하니? – Kallmanation

+0

@Glubus, 당신이 더 나은 대답이 될 것이라고 생각하는 것을 정교 할 수 있다면, 나는 항상 배우기를 원합니다. – Kallmanation

0

귀하의 경우와는 제대로 작동하지만

<?=l(273)?> 

가 작동하지 않습니다. "난"사용자 정의 함수 인 경우 대신

<? l(273);?> 

을 사용하고 작동합니다.

+1

어떻게 작동하지 않는지 상세히 설명해주세요. 아마도 l()은 바깥 쪽 범위에 정의 된 함수입니다. – Glubus

+0

감사합니다. 단지 현지화 코드입니다. 정상적으로 작동합니다. – erics15

0

시도해보십시오. 문제가 해결 될 수도 있습니다.

<?php 

// true 
if ($perms['user_profiles|edit_billable']===TRUE) { 

?> 
<div class="field"> 
    <label><?php=l(273)?></label> 
    <div class="input"> 
      <input type="checkbox" name="billable" value="1" data-bind="checked: userProfile().billable, disable:isBillable();"> 

    </div> 
    </div> 
</div> 


<?php 


}elseif ($perms['user_profiles|edit_billable']===FALSE){ 
// false 
    ?> 

<div class="field"> 
    <label><?php=l(273)?></label> 
    <div class="input"> 
<!-- This is where the else would go -->  
      <input type="checkbox" name="billable" value="1" data-bind="checked: userProfile().billable, enable:isBillable();"> 

    </div> 
    </div> 
</div> 



<?php 
} 
?> 
관련 문제