2016-03-28 87 views
1

我奮力定義,我放在laravel文件夾結構在我的推證書路徑中的推證書路徑:尋找laravel

config/ios-push-notification-certificates/certificate.pem

在我APNS類我想找到正確的道路用它來推動,那麼:

class APNS { 
private $certificate = __DIR__ . "/ios-push-notification-certificates/production/certificate.pem"; 
(...) 
} 

但我得到一個錯誤:

syntax error, unexpected '.', expecting ',' or ';'

如何正確引用路徑?

我想:

private $certificate = config_path() . "/ios-push-notification-certificates/production/certificate.pem"; 

但這返回錯誤

expression is not allowed as field default value

+0

您必須將成員變量初始化爲靜態。你可以在類之外定義它,'define('CERTIFICATE_FILE',__DIR__。'/ /certificate.pem');'然後'class APNS {private $ certificate = CERTIFICATE_FILE;' – Cyclonecode

回答

1

要訪問您的certificat文件config/ios-push-notification-certificates/certificate.pem 就可以直接使用config_path($path)這樣的:

private $certificate = config_path("ios-push-notification-certificates/certificate.pem"); 

這等於/laravel_app_path_in_your_pc/config/ios-push-notification-certificates/certificate.pem(a絕對路徑)

+0

雖然你的回答可能是正確的,嘗試添加一兩句解釋原始錯誤或您不同的方法。沒有任何評論的代碼通常不是一個好的答案。 –

+1

@ChristianKönig好的,我做到了 –