2016-03-05 118 views
0

我試過很多次這個錯誤以不同的方式也嘗試了一個溶劑:CakePHP: Call to a member function setFlash() on a non-object url ...但是這個解決方案在我的項目中也不起作用。調用成員函數成功()在非對象上

無法識別最新的錯誤。 !

這裏是我的user.php的模型

class User extends AppModel { 

public $helpers = array('Html','Form'); 
public $components = array('Email','Flash','Session'); 


public function send_mail($useremail){ 

    $Email = new CakeEmail('gmail'); 

    $Email->emailFormat('html') 
      ->from('[email protected]') 
      ->to($useremail) 
      ->subject('User subject'); 
    if($Email->send("123")){ 
     $this->Flash->success(__('Mail Sent')); // **this line cause error** 
    }else{ 
     $this->Session->setFlash('Problem during sending email'); 
    } 
} 
} 
+0

來改變它試試這個$ this-> Flash-> success(「Mail Sent」); –

回答

2

如文檔建議,FlashComponent提供了兩種方式來設置閃光燈的消息:其__call()魔術方法及其 set()方法。爲了提供詳細的應用程序,FlashComponent的__call()魔術方法允許您使用映射到位於src/Template/Element/Flash directory下的元素的方法名稱。按照慣例,方法,駝峯將映射到小寫並強調元素名稱:

//使用的src /模板/元/閃光燈/ success.ctp

$this->Flash->success('This was successful'); 

//使用SRC /模板/元/閃光燈/ great_success.ctp

$this->Flash->greatSuccess('This was greatly successful'); 

或者,要設置一個純文本消息無需渲染的元素,可以使用set()方法:

$this->Flash->set('This is a message'); 

,因此,需要通過鍵入

$this->Flash->success('Mail sent'); 
+0

親愛的朋友。謝謝你的寶貴建議......我嘗試了你提到的所有建議,但沒有一個人正在工作! ..可以說,如果我使用$ this-> Flash-> set(),那麼它會在非對象錯誤上生成set();反之亦然,它會在非對象錯誤時生成成功()! –

+0

@MrudangShah嘗試在類用戶 'App :: uses('CakeEmail','Network/Email')中添加這個陳述;'和lemme知道它是否工作。 –

+0

已添加... –

相關問題