2016-04-25 8 views
-1

ich für diese bekommen weniger infomesion suchen, während ichYII2 RESTFUL 404

  • meine config (rest.php)

    <?php 
    $params = require(__DIR__ . '/params.php'); 
    $config = [ 
        'id' => 'rest-api', 
        'basePath' => dirname(__DIR__), 
        'language' => 'zh-CN', 
        'controllerNamespace' => 'rest\controllers', 
        'bootstrap' => ['log'], 
        'modules' => [ 
         'v1' => [ 
          'class' => 'rest\versions\v1\Module', 
        ], 
    ], 
    'components' => [ 
    
        'errorHandler' => [ 
         'errorAction' => 'site/index', 
        ], 
        'urlManager' => [ 
         'enablePrettyUrl' => true, 
         'enableStrictParsing' => true, 
         'showScriptName' => false, 
         'rules' => [ 
          [ 
           'class' => 'yii\rest\UrlRule', 
           'controller' => [ 
            'v1/product', 
           ], 
          ] 
         ], 
        ], 
        'log' => [ 
         'traceLevel' => YII_DEBUG ? 3 : 0, 
         'targets' => [ 
          [ 
           'class' => 'yii\log\FileTarget', 
           'levels' => ['error', 'warning'], 
          ], 
         ], 
        ], 
        'db' => require(__DIR__ . '/db.php'), 
        'request' => [ 
         'parsers' => [ 
          'application/json' => 'yii\web\JsonParser', 
         ] 
        ], 
    ], 
    'params' => $params, 
    ]; 
    return $config; 
    
  • mein module.php

    <?php 
    namespace rest\versions\v1; 
    
    use Yii; 
    use yii\base\Module; 
    class Module extends Module 
    { 
        public $controllerNamespace = 'rest\versions\v1\controllers'; 
    
        public function init() 
        { 
        parent::init(); 
        } 
    } 
    
  • tun
  • meine .htaccess-Datei, es ist Code wie folgt.

    Options +FollowSymLinks 
        IndexIgnore */* 
    
        RewriteEngine on 
    
        # if a directory or a file exists, use it directly 
        RewriteCond %{REQUEST_FILENAME} !-f 
        RewriteCond %{REQUEST_FILENAME} !-d 
    
        # otherwise forward it to index.php 
        RewriteRule . index.php 
    

    MY Produktcontroller

    <?php 
        namespace rest\versions\v1\controllers; 
    
        use Yii; 
        use yii\rest\ActiveController; 
    
        class ProductController extends ActiveController 
        { 
        public $modelClass = 'rest\versions\v1\models\Product'; 
    
        public function actionIndex() 
        { 
         return 'haha'; 
        } 
    
        } 
    

Ich bekomme immer noch die 404

http://rest.mcolor.com/v1/products

ich die Info bekam

  404 Not Found 

     nginx/1.8.1 

plz hilf mir.

Antwort

0

Es sieht aus wie Sie .htaccess-Datei für Neufassungen verwenden, aber auf dem Server Nginx Web-Server installiert ist (Sie, dass bei 404 Antworttext sehen können.)

So können Sie aus einige Beispiel von nginx config Tutorial und Änderung Domains, Pfad, etc:

server { 
charset utf-8; 
client_max_body_size 128M; 

listen 80; ## listen for ipv4 
#listen [::]:80 default_server ipv6only=on; ## listen for ipv6 

server_name mysite.local; 
root  /path/to/basic/web; 
index  index.php; 

access_log /path/to/basic/log/access.log; 
error_log /path/to/basic/log/error.log; 

location/{ 
    # Redirect everything that isn't a real file to index.php 
    try_files $uri $uri/ /index.php?$args; 
} 

# uncomment to avoid processing of calls to non-existing static files by Yii 
#location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ { 
# try_files $uri =404; 
#} 
#error_page 404 /404.html; 

location ~ \.php$ { 
    include fastcgi_params; 
    fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name; 
    fastcgi_pass 127.0.0.1:9000; 
    #fastcgi_pass unix:/var/run/php5-fpm.sock; 
    try_files $uri =404; 
} 

location ~ /\.(ht|svn|git) { 
    deny all; 
} 

}

+0

danke @ s_mart – user6249525