2016-10-03 4 views
0

다음 parenthese로 데이터를 전달하여 전자 메일 codeigniter 전자 메일 클래스를 보내려고합니다.Codeigniter 전자 메일 클래스 예기치 경우

$this->email->message('Whatever message you want to email') 

다음 작품

$this->email->message('Your name is '.$data->name.''); 

하지만 다음과 같은 오류를 줄 것이다. "예기치 않은 경우"

$this->email->message('You have ordered:'. 
         if(isset($result->order)){ 
          //show order detail 
         }else{ 
          "nothing" 
         }.''); 

올바른 방법은 무엇입니까?

그리고 foreach 루프를 if(isset 뒤에 어떻게 포함시키려는 경우에도 어떻게 작동할까요?

+0

'경우() {}'블록에 대한 올바른 위치에 있지된다. [ternary 운영자] (https://davidwalsh.name/php-shorthand-if-else-ternary-operators)를 살펴볼 수 있습니다. – MonkeyZeus

답변

2

if아니요입니다. 변수 할당을위한 "데이터 소스"로 사용할 수 없습니다.

$foo = if(...) { ... } // illegal syntax. 

if (...) { 
    $foo = true result 
else { 
    $foo = false result 
} 

$this->email->message('You have ordered:'. $foo); 
1

당신은 "삼항 연산자"를 찾고 있습니다로 작성해야 : 분명히 여기

<?php 
$this->email->message('You have ordered: ' . isset($result->order) ? '...' : 'nothing'); 

'...' 당신이 원하는대로 "세부 사항"에 대한 유일한 자리 표시 자입니다 표시합니다. 이것은 확실히 이전에 준비된 문자열 변수가 될 수 있습니다.

http://php.net/manual/en/language.operators.comparison.php

+0

나는 이것이 이것일지도 모른다라고 생각한다. 나는 그것을 아직 시도하지 않았다. 그러나 그것은 무엇을한다? do do – codenoob

+0

글쎄, 내가 참조한 문서를 보자. 그것은 왼쪽에있는 피연산자를 평가하고 그것이 맞는지 아닌지를 결정한다. 그것에 따라 오른쪽에서 첫 번째 (true) 또는 두 번째 (false) 대안을 선택합니다. – arkascha

0

그것은이 같을 수 :

$temp = isset($result->order) ? "" : "nothing"; 

$this->email->message('You have ordered:'.$temp.'');