我想将数据库变量传递给中间件功能。然而,我发现了以下错误:如何将变量传递给中间件功能? [SLIM框架]
Fatal error: Call to undefined method Slim\Route::prepare() in /Applications/MAMP/htdocs/website/models/feedback.php on line 11 with the code: "$results = $db->prepare("INSERT INTO ... "
的代码如下:
function newsletter(){
$app = \Slim\Slim::getInstance();
$route = $app->request->post('route');
$email = $app->request->post('email_subscribe');
$subscribe = $app->request->post("subscribe");
$oFeedback = new Feedback();
if(!empty($email)) {
$cleanEmail = filter_var($email, FILTER_SANITIZE_EMAIL);
$type="newsletter";
$oFeedback->saveFeedback($db,NULL,$cleanEmail,NULL,$type);
}
}
我打电话中间件功能的路线是这样的:
$app->post('/triparticle', 'newsletter', function() use($app, $db){
})->name("triparticle_post");
你能帮我么?
如果您可以在$ app中显示嵌套变量的示例以及如何在中间件内访问这些变量,那么您的答案会更有帮助。 –