如何构建一个app.yaml文件? [英] How to construct a app.yaml file?

查看:153
本文介绍了如何构建一个app.yaml文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试GAE for php,并在app.yaml文件构造中迷路了。我可以理解Google教程中的部分内容,它显示了如何将所有网址请求指向一个文件。



(您不需要通配符用于样式表,JavaScript和图像,因为您已经使用了static_dir对于那些。)


I am trying out GAE for php and got lost in the app.yaml file construction. I can understand the part from the google tutorial which shows how to point all url request to a single file

https://developers.google.com/appengine/docs/php/gettingstarted/helloworld

But it does not help in my case. I am going to post what I have setup and the file structure is in the pic.

App.yaml

application: xxx
version: 1
runtime: php
api_version: 1
threadsafe: true

handlers:
- url: /stylesheets
  static_dir: stylesheets

- url: /images
  static_dir: images

- url: /scripts
  static_dir: scripts

- url: /favicon.ico
  static_files: favicon.ico
  upload: favicon.ico

- url: /
  script: main.php
  login: required
  auth_fail_action: redirect

- url: /main
  script: main.php
  login: required
  auth_fail_action: redirect

So my landing page for xxx.appspot.com or xxx.appsport.com/main would be main.php. And it works fine.

main.php

<?php
session_start();
date_default_timezone_set('America/Los_Angeles');
require_once 'google/appengine/api/users/UserService.php';

use google\appengine\api\users\User;
use google\appengine\api\users\UserService;

$user = UserService::getCurrentUser();
$name= $user->getNickname();
$name = explode(".",$name);
$name[0]= ucfirst($name[0]);
$name[1]= ucfirst($name[1]);
$name = $name[0]." ".$name[1];
$_SESSION['name']=$name;
$_SESSION['email']= getenv('USER_EMAIL');

header('Location: login.php');

So it loads starts a session and gets the user name and email do a few string formatting and then set as Session variable and then I check to match a condition and based on the condition redirect to another script which does some more validation and so on. To make is simple I am just redirecting it to login.php

login.php

<?php
session_start();
echo $_SESSION['name'];

So the out put displayed should be the session variable name but instead I get this

So what did I do wrong? I am going to use the login page to pull user data from a SQL db and based on the value redirect the user to different pages which will display different forms, tables, reports based on their settings.

Eg. From login.php

if userA belongs to Dept1

header('Location: /Dept1/main.php');

Else

header('Location: /Deptx/main.php');

So I expect a lot of redirects and each of the redirects must be able to also carry over the session variables that are set. I as able to do this while running on normal PHP server. The GAE version requires some re learning. I would like to thank any one in advance just for taking time to read till hear. Thank you.

Also it would be nice if some one could do a detail tutorial on how to use app.yaml and how it could be used with a demo example like in w3school.

解决方案

Your app.yaml is looking good; it's just incomplete.

You've defined that "/" and "/main" map to your main.php script, and that works fine.

But when the user's browser requests "/login.php", App Engine looks in app.yaml and does not find any route that matches, so you get this 404 error.

To handle this particular case, you can another entry with "url: /login.php" and "script: login.php".

Then I would look through your application and make sure you're not missing any other routes.

You also may need to use wildcards in your URLs in app.yaml. Otherwise, if your application ever sends the user to a URL like "/main/subpage", it will not go to the main.php handler because it matches no routes in app.yaml. In this case you might want to use "url: /main.*", as an example. Or you can use a catchall "/.*" handler at the end of your app.yaml.

You can learn about these wildcards and the other app.yaml options on the PHP app.yaml reference page: https://developers.google.com/appengine/docs/php/config/appconfig

(You don't need wildcards for your stylesheets, javascript, and images, though, because you've used static_dir for those.)

这篇关于如何构建一个app.yaml文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆