FuelPHPを使って、URLにGETで渡されたuser_idから、
usersテーブル内に存在するuser_idがあれば、
user情報を(user_id/username)をjsonで出力するapiを作っています。
ただ、うまく動作せず困っています。
localhost:3000/users/1にアクセスして、
user_idのユーザ情報を出力したいです。
アクセスするURLのイメージとしては、
localhost:3000/users/1
というように/users/1というURLにアクセスした時に
(localhost:3000/users/?user_id=1と同等)
user_idが1のユーザの情報をJSONで出力するイメージです。
具体的にFuel側では、
Controller_Restを継承し、Controller_Usersを作りました。
fuel/app/classes/controller/users.php
Controller_Usersのaction_indexメソッドには、
usersテーブル内に存在するuser_idがあれば、
user情報を(user_id/username)をjsonで出力する処理が書かれて有ります。
以下nginxファイルです。
lang
1server { 2 listen 80; 3 server_name localhost; 4 5 #charset koi8-r; 6 #access_log /var/log/nginx/log/host.access.log main; 7 root /var/www/api/public; 8 index index.php index.html index.htm; 9 location /users/ { 10 #root /var/www/api/fuel/app/classes/controller/; 11 # Rewrite for FuelPHP 12 13 if (-f $request_filename) { 14 expires 30d; 15 break; 16 } 17 if (!-e $request_filename) { 18 rewrite ^(.*)$ /index.php?q=$1 last; 19 } 20 } 21 location ^/users.php { 22 root /var/www/api/fuel/app/classes/controller/; 23 rewrite ^/users/([0-9]+)$ /users/?id=$1 last; 24 } 25 #error_page 404 /404.html; 26 27 # redirect server error pages to the static page /50x.html 28 # 29 error_page 500 502 503 504 /50x.html; 30 location = /50x.html { 31 # root /usr/share/nginx/html; 32 root /var/www; 33 } 34 35 # proxy the PHP scripts to Apache listening on 127.0.0.1:80 36 # 37 #location ~ \.php$ { 38 # proxy_pass http://127.0.0.1; 39 #} 40 location ~ \.php$ { 41 #rewrite ^/users/([0-9]+)$ /users/?id=$1 last; 42 #root /var/www; 43 root /var/www/api/public; 44 fastcgi_pass 127.0.0.1:9000; 45 fastcgi_index index.php; 46 # fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 47 # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; 48 # fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name; 49 # fastcgi_param SCRIPT_FILENAME /var/www/api/public$fastcgi_script_name; #安定 50 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 51 include fastcgi_params; 52 } 53}
何か解決策・アドバイス宜しくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/05/04 08:05
2015/05/04 08:45