php中的路由不起作用

时间:2015-10-14 13:40:01

标签: php slim

对于php来说还是一个新手,请原谅我的无知。

上下文

服务器使用php slim作为子模块,即该服务器嵌套在一些其他文件夹中,该文件夹代表一个更大的应用程序服务器(确切地说是moodle)。所以文件目录如下

$app->get(
    '/',
    function () {
        echo "basic test text";
    }
); 

问题/困惑

基本网址

localhost/moodle/module/submodule/phpserver/api/ 

因此,如果我输入

,这会将基本测试文本返回给浏览器
$app->get(
    '/Count_Schools',
    function () {
        echo "sample count";
    }
);

但是任何其他路线都会返回404,例如

$app->hook('slim.before', function () use ($app) {
    $app->view()->appendData(array('baseUrl' => '/localhost/moodle/report/api'));
});

这将返回404。

我不太确定唯一的基本网址是如何工作的。

决议失败

明确设置基本网址

require 'Slim/Slim.php';
require 'db.php';
\Slim\Slim::registerAutoloader();

$app = new \Slim\Slim();
$app->hook('slim.before', function () use ($app) {
    $app->view()->appendData(array('baseUrl' => '/localhost/moodle/report/api'));
});

// GET route
$app->get(
    '/',
    function () {
        echo "basic test text";
    }
);
$app->get(
    '/Count_Schools',
    function () {
        echo "sample text";
    }
);

设置

# On some PHP servers it may help if this file is copied
# to the main moodle directory and renamed .htaccess
#
# As soon as you do this, check your web site.  Is it
# still working OK?  If you are getting a "configuration
# error" then you may need to enable overrides by editing
# the main httpd.conf for Apache and in the main server
# or virtual server area, adding something like:
#
# <Directory /web/moodle>
#     AllowOverride All
# </Directory>
#

### Firstly, if you are using Apache 2, you need the following
### three lines to allow Apache to pass a PATH_INFO variable
### correctly for URLs like http://server/file.php/arg1/arg2

<IfDefine APACHE2>
    AcceptPathInfo on
</IfDefine>

### Secondly, you can define the default files in the Moodle
### directories as follows:

DirectoryIndex index.php index.html index.htm

### Thirdly, set up some PHP variables that Moodle needs

php_flag file_uploads            1
php_flag short_open_tag          1
php_flag session.auto_start      0
php_flag session.bug_compat_warn 0

### Fourthly, sometimes Apache limits the size of uploaded files
### (this is a separate limit to the one in PHP, see below).
### The setting here turns off this limitation

LimitRequestBody 0


### These are optional - you may not want to override php.ini
### To enable them, remove the leading hash (#)

#php_value upload_max_filesize 2M
#php_value post_max_size 2M
#php_value session.gc_maxlifetime 7200


### You can change the following line to point to the
### error/index.php file in your Moodle distribution.
### It provides a form which emails you (the admin)
### about 404 errors (URL not found).

#ErrorDocument 404 http://example.org/moodle/error/index.php


### People have reported that these can help in some cases
### (unusual) when you see errors about undefined functions

#php_value auto_prepend_file none
#php_value include_path .

htaccess的

/var/www/html/moodle/lib

注意:我没有为我的项目创建一个htaccess,这是较大项目的htacceess。因此它保存在

{{1}}

0 个答案:

没有答案