This sample is part of the Learn Forge tutorials.
For using this sample, you need an Autodesk developer credentials. Visit the Forge Developer Portal, sign up for an account, then create an app. For this new app, use http://localhost:3000/api/forge/callback/oauth as Callback URL, although is not used on 2-legged flow. Finally take note of the Client ID and Client Secret.
Now we need an IDE to write the code. There are many options, this sample will use Visual Studio Code.
For this sample, use all default install options.
Next, install the extension of PHP Server & PHP Debug for Visual Code, this can help debug your PHP project.
- Go to Visual Code extension manager (left side, bottom icon)
- Type
PHPand installPHP Server&PHP Debugplugins.
Install PHP.
Install �Composer.
Clone this project or download it. It's recommended to install GitHub desktop. To clone it via command line, use the following (Terminal on MacOSX/Linux, Git Shell on Windows):
git clone https://github.com/autodesk-forge/forge.learning.viewmodels.php
To run it, follow the steps:
- install the required packages by composer install;
- rename .env.example to .env, and set the FORGE_CLIENT_ID & FORGE_CLIENT_SECRET with your Forge client ID & secret;
- open the Command Palette from VS Code, and run the command Serve Project With PHP, it will start PHP server at port 3000.
- open your browser and go to
http://localhost:3000
Define config vars from your Forge App Key with the following command in Heroku:
- heroku config:set FORGE_CLIENT_ID="YOUR CLIENT ID FROM DEVELOPER PORTAL"
- heroku config:set FORGE_CLIENT_SECRET="YOUR CLIENT SECRET FROM DEVELOPER PORTAL"
Open the live demo at https://forgeviewerphp.herokuapp.com
- The Autodesk Forge packages is included by default.
- The klein is used for router.
- The phpdotenv is used to load environment variables from
.envtogetenv(),$_ENVand$_SERVERautomagically.
We rewrite the url to have a clean url. to config that: For Apache, .htaccess is added to do url rewrite.
If you want to work with Nginx, open nginx.conf, find the server, add the following code in server{ location/{ } }
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
Note: If Composer command can not be recognized after installation, please move and rename composer.phar to folder /usr/local/bin/ with the following command:
$ mv composer.phar /usr/local/bin/composer
Check the detail at Answer on StackOverflow.
This sample is licensed under the terms of the MIT License. Please see the LICENSE file for full details.
Zhong Wu @JohnOnSoftware, Forge Partner Development