如果我按照你的要求,你只需要兩次相同的路線:一個用於獲取(顯示錶單)和一個用於處理它。在後控制器中,您只需包含您的pageX_process.php,您應該準備好了。
在Silex的代碼翻譯應該是這樣的:
<?php
/**
* if you're using silex-skeleton
* from: https://packagist.org/packages/fabpot/silex-skeleton)
* this file should be src/controllers
*/
// standard setup, like error handling and other route declarations
$app->get('/page1', function() use ($app) {
// you're currently using this (somehow)
$params = []; //set up your template parameters here
return $app['twig']->render('page1.twig', $params);
});
$app->post('/page1_proccess', function() use($app) {
ob_start();
require PATH_TO_LEGACY_FILES_DIR . '/page1_process.php';
return ob_get_clean();
});
從現在開始,如果你想/找到它足夠的,你就可以開始重構你pageX_process.php頁面更OOP/Silex的方式,但你有這個應用程序架構的起點。
注意:
- ,則應該從web目錄移開你的php文件(例如傳統的/在你的項目的根目錄)
- 您必須指向你的表單處理的腳本(動作參數)到新的路線(你可以使它使用舊路線也工作,但需要一點點努力)
我會試試這個。謝謝。 – nobrandheroes 2015-02-10 15:04:56