0
我需要設置變量的建議。我使用Slim框架。我幾乎沒有上課。功能函數內的PHP設置變量
MailboxManager.php
public function getMailById($id) {
/* @var $sql PDOStatement */
$sql = $this->database->prepare("SELECT * FROM appmail_mails WHERE id = :id");
$sql->bindParam('id', $id);
$sql->execute();
$record = $sql->fetch(PDO::FETCH_ASSOC);
if ($record === false) {
return null;
}
$mail = new Mail($id);
$mail->setMailContent($record['content']);
$mail->setMailDate($record['date']);
$mail->setMailSubject($record['subject']);
$mail->setMailSize($record['
return $mail;
MailController.php
class MailController
private $id;
public function showMail()
$mail = ServicesFactory::getMailboxManager()->getMailById($this->id);
echo "<pre>";
var_dump($mail);
現在我要搭配修身框架創建路徑。在指數PHP我放:
$app->get('/dupa/{id}', function(ServerRequestInterface $request){
$id = $request->getAttribute('id');
echo $id;
$new = new MailController();
$test = $new->showMail();
var_dump($test);
});
我怎麼來設置ID:
$mail = ServicesFactory::getMailboxManager()->getMailById($this->id);
妥善得到它? 每次我試圖:
$test = $new->showMail($id)
我只是得到空。
感謝您的幫助。
你'showMail()'不會返回任何東西? –
是的,它返回null –
你的函數'showMail()'不期望任何id。您如何期待MailController獲取該ID? – hasumedic