Use some basic PHP in parse.com static content hosting - php

I want to be able to run some PHP code in my mostly static webpage, my Parse project looks like this:
.
├── LICENSE
├── README.md
├── cloud
│   └── main.js
├── config
│   └── global.json
└── public
├── confirmation.html
├── contact.php
├── contactsettings.php
├── css
├── experiencias
├── fonts
├── img
├── index.html
├── js
├── redirect.html
├── subscribe.php
└── thanks.html
So as you can see, I have some PHP code to run, yet when trying to, Parse gives me the following error:
Page not found
This Parse App does not have a page at the requested URL.

Like mentioned in a comment by #nathancahill, Parse.com STATIC webhosting does not support PHP code.
PHP code is dynamic and not static content.
To host a dynamic website on Parse, you can use Cloud Code or Express.
Read more here: https://parse.com/docs/hosting_guide#webapp

Related

How to use controller from parent directory in laravel

I have a folder structure like this:
Controller/
├── API/
│ ├── APIController.php
│ └── APIFunction.php
├── OTPController.php
├── LoginController.php
└── HomeController.php
I'm trying to call a method from OTPController.php within my APIController.php:
$otpController = new App\Http\Controllers\OTPController();
But it returns an error:
Class 'App\Http\Controllers\API\App\Http\Controllers\OTPController' not found in file /var/www/app/Http/Controllers/API/APIController.php

Composer autoloader doesn't load class when I use variable

I've used autoloader from composer. Everything is fine when I set class name directly
<?php
namespace Matrix;
$router = new Router;
$object = $router->object;
$method = $router->method;
$id = $router->id;
$action = new Accounts();
It works. But if I try to set variable as a class name
$action = new $object();
it returns Fatal error: Uncaught Error: Class 'Accounts' not found.
var_dump($action);
returns string 'Accounts' (length=8)
Section autoload in my composer.json:
"autoload": {
"psr-4": {
"Matrix\\": "matrix/controllers/"
}
My directories structure:
├── matrix
│   ├── controllers
│   │   ├── Accounts.php
│   │   ├── BaseController.php
│   │   ├── OffersController.php
│   │   ├── RefreshController.php
│   │   └── Router.php
│   ├── index.php

How to change the app path to api in Laravel 5 directory structure

In Laravel 5 I'd like to change the default directory structure, so the path for app I want to move it to something like api, how can I accomplish this?
Example, instead of this structure:
.
├── app
├── bootstrap
├── config
├── database
├── public
├── resources
├── storage
├── tests
└── vendor
I want this:
.
├── api
├── bootstrap
├── config
├── database
├── public
├── resources
├── storage
├── tests
└── vendor
In my composer I've changed the namespace like so, as following this question: How to change app folder name in laravel 5:
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"Api\\": "api/"
}
},
But I'm getting the error:
[RuntimeException]
Unable to detect application namespace.
Well, after a while I found a way to accomplish this, after look around for other answers like this I figured out that the app path is hardcoded in Application::path() see the source
Then I could make it work by overriding the Application::path() method:
class Application extends \Illuminate\Foundation\Application
{
/**
* Overrides the path to the application "app" directory.
*
* #return string
*/
public function path()
{
return $this->basePath.DIRECTORY_SEPARATOR.'api';
}
}
Then update the bootstrap/app.php:
// Overrides the PATH to use api instead of app
$app = new Api\Application(
realpath(__DIR__.'/../')
);
Now I can have the following structure:
.
├── api
├── bootstrap
├── config
├── database
├── public
├── resources
├── storage
├── tests
└── vendor
A similar method was found in https://mattstauffer.co/blog/extending-laravels-application
In Laravel 5.7 you can now use $app->setAppPath($path), like so:
$app->useAppPath(realpath(__DIR__ . '/../api'));
This can be called from bootstrap/app.php.

Issue starting with Slim 2

I'm developing a web service using Slim Framework 2, it's the first time I use php. I'm having an issue with the Slim object:
There's my code:
require 'db.php';
require 'vendor/slim/slim/Slim/Slim.php';
echo 'require ok';
$app = new vendor/slim/slim/Slim();
echo '$app ok';
The 'require' lines are ok. But he $app line doesn't work I use the same path to the Slim.php file and also I've tryed to use this path:
$app = /slim/Slim();
The first echo is executing but the second one is not working. My ws.php file is on the same directori as the vendor folder:
vendor/slim/slim/Slim/
├── Environment.php
├── Exception
│   ├── Pass.php
│   └── Stop.php
├── Helper
│   └── Set.php
├── Http
│   ├── Cookies.php
│   ├── Headers.php
│   ├── Request.php
│   ├── Response.php
│   └── Util.php
├── Log.php
├── LogWriter.php
├── Middleware
│   ├── ContentTypes.php
│   ├── Flash.php
│   ├── MethodOverride.php
│   ├── PrettyExceptions.php
│   └── SessionCookie.php
├── Middleware.php
├── Route.php
├── Router.php
├── Slim.php
└── View.php
Is $app = new vendor/slim/slim/Slim(); correct? I'm lost about this topic.
Solved using Frank Martin solution:
require 'vendor/autoload.php';
$app = new \Slim\App;
Instead:
require 'vendor/slim/slim/Slim/Slim.php';
$app = new vendor/slim/slim/Slim();
Regards
Make sure you've installed the composer dependencies then use this instead.
require 'vendor/autoload.php';
$app = new \Slim\App;

Mustache_Engine not loading, conflict due to setting namespace?

The code below is me attempting to load Mustache into a Composer library (meaning the library itself is also being loaded by composer by the full project) I'm making for a project.
<?php
namespace TradeDefender\SiteEngine;
require '../../vendor/autoload.php';
class MessageEngine{
function test(){
$m = new Mustache_Engine;
return "hello";
}
}
?>
The directory structure for the library itself looks like this:
.
├── lib
│   └── TradeDefender
│   ├── Api
│   ├── Conn
│   └── SiteEngine
└── vendor
├── composer
└── mustache
I'm suspecting that it's due to me setting a namespace in the class, but I'm not sure how to fix it. The error itself is that it's not able to find the Class Mustache_Engine in the SiteEngine folder. The autoloader itself is being loaded just fine.
Any ideas? Thanks.
The problem was that I was loading the Mustache_Engine from the locally defined namespace rather than the global namespace. To load from the global namespace I had to put a \ infront of Mustache_Engine, like so:
$m = new \Mustache_Engine;

Categories