[英]how can I set a session variable in Drupal 8 and get it in a php script?
我在 drupal 的自定義模塊中工作 8. 我有一個表單,我試圖通過提交按鈕將一些數據從我的自定義模塊發送到另一個 php 腳本文件:
$form['submit2'] = [
'#type' => 'submit',
'#value' => t('editor'),
'#access' =>isset($_GET['id']) ? true:false,
'#submit' => ['::goto_editor']
];
....
public function goto_editor() {
$session = \Drupal::request()->getSession();
$session->set('value', 'hi');
}
現在我想獲取另一個 PHP 文件中的值。 如何將我的 PHP 腳本連接到 Drupal 8.x session 服務? 非常感謝。
私人臨時商店會滿足您的需求嗎? 在您的情況下,您可能會像這樣設置值:
$tempstore = \Drupal::service('tempstore.private')->get('your_module_name');
$tempstore->set('value', 'hi');
然后在你的第二個 PHP 文件中這樣獲取它:
$tempstore = \Drupal::service('tempstore.private')->get('your_module_name');
$some_data = $tempstore->get('value');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.