SlimPHP和路由 - 我做错了吗?

时间:2015-04-30 20:27:49

标签: php .htaccess frameworks routing

所以我最近,就像在大约一天前,询问了为什么我的routes were not working for slim并根据答案,我做了相应的更改,但除非我做错了路线,否则他们不工作。< / p>

如果我们查看我已设置的路由文件(index.php文件中需要),我们可以看到:

<?php
use \ImageUploader\Controllers as Controller;
/** ---------------------------------------------------------------- **/
// Routes.
//
// Routes are defined here. Nothing should happen in a route other then
// Calling  acontroller based action, such as: indexAction.
/** ---------------------------------------------------------------- **/
$app = new \Slim\Slim();

$app->get('/', function(){
    Controller\HomeController::showHome();
});

$app->get('/signup', function(){
    Controller\SignupController::showSignupForm();
});

$app->post('/signup/new', function() use ($app){
   var_dump($app->request()->post('username'));
   var_dump($app->request()->post('password'));
});

// Don't touch.
$app->run();

我列出了几条路线。现在我可以转到第一个,它会显示HomeController::showHome的内容,但如果我尝试导航到http://localhost/image-upload/signup,我会得到:

Not Found

The requested URL /image-upload/signup was not found on this server.

现在我的项目不在根目录中,它位于图片上传中,所以当我去localhost / image-upload时,我看到了/路由执行结果。

我的htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /image-upload/

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
</IfModule>

我的index.php文件也是如此:

<?php
/** ---------------------------------------------------------------- **/
// This is the core app.
/** ---------------------------------------------------------------- **/
if (!file_exists('bootstrap.php')) {
    throw new \Exception('Where is the bootstrap.php?');
}

require_once 'bootstrap.php';

/** ---------------------------------------------------------------- **/
// Routing.
/** ---------------------------------------------------------------- **/
require_once 'app/routes.php';

我做错路由还是......

所做的更改

修正了重写基础,假设是/ image-upload /。这怎么都没有解决任何问题。 Mod Rewrite已启用并打开。

有人提出了苗条核心路线的待定image-upload/(或类似)。这没有用。实际上它打破了路由。

1 个答案:

答案 0 :(得分:2)

你可以尝试一下吗?

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?/$1 [L,QSA]
相关问题