I am following a tutorial from here:
https://www.simplifiedcoding.net/php-restful-api-framework-slim-tutorial-1/
The tutor said download slim at:
https://github.com/slimphp/Slim
Everything seems ok now but when I try to load the REST at Mozilla's REST easy app. I was given the error:
Warning: require(.././libs/Slim/Slim.php): failed to open stream: No such file or directory in C:\xampp\htdocs\StudentApp\v1\index.php on line 5
Fatal error: require(): Failed opening required '.././libs/Slim/Slim.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\StudentApp\v1\index.php on line 5
I checked the Slim directory and Slim.php is really missing. Can anyone pls help me. Thanks.
Instead of Slim.php and \Slim\Slim(), just use App.php and \Slim\App() as mentioned in the documentation of Slim.
To Explain Well
Use:
require 'vendor/autoload.php';
Instead of:
require '.././libs/Slim/Slim.php';
And use:
$app = new \Slim\App();
Instead of:
$app = new \Slim\Slim();
I have found a solution. What I did is that I downloaded the Slim-2x version from here:
https://github.com/codeguy/Slim
I copied the Slim.php of the Slim-2x to the Slim-3x. It worked but I think there are better solution for this.
Related
I have uploaded website to o2switch host.
When I worked on localhost, all worked well.
But on o2switch, I have this error :
Warning: require_once(models/shopManager.class.php): failed to open stream: No such file or directory in /home/myUserNameo2switch/myDomain.fr/controllers/ShopController.controller.php on line 2
Fatal error: require_once(): Failed opening required 'models/shopManager.class.php' (include_path='.:/opt/alt/php73/usr/share/pear') in /home/myUserNameo2switch/myDomain.fr/controllers/ShopController.controller.php on line 2
I use MVC model with file structure like :
index.php
-controllers
-ShopController.controller.php
-models
-shopManager.class.php
In my index.php I do :
require_once "controllers/ShopController.controller.php";
$shopController = new ShopController();
In ShopController.controller.php, I do :
require_once "models/shopManager.class.php";
On o2switch PHP setting (I think similar to php.ini) there is configuration for include_path equal to .:/opt/alt/php73/usr/share/pear
The trouble is it coming from include_path value ?
That's the first time I work on online website and my first question here. Sorry if I am clumsy. Thank you
In ShopController.controller.php, you can try to change
require_once "models/shopManager.class.php";
to
require_once "../models/shopManager.class.php";
to see if the error message would disappear.
Thanks ild flue for your answer. It doesn't work.
My trouble is fixed. I had a trouble with capital and not capital letter between file and file called on require_once... :(
The most surprising is I had no error on local.
This might be a dummy question now but bevertheless giving it a try: I am just trying to setup scssphp in my cakephp 4 but seem to have a knot in my head. Can anymone shed some light on what I need to do to get it running?
My simple idea was to just include the code below into the app controller initialize function
<?php
require "scssphp/scss.inc.php";
$scss = new scssc();
$scss->setImportPaths("stylesheets/");
// will search for `stylesheets/style.scss'
echo $scss->compile('#import "style.scss"');
And I create the "scssphp" folder structure with the "scss.inc.php" right under webroot:
webroot/scssphp/scss.inc.php
webroot/scssphp/style.php
webroot/scssphp/stylesheets/style.scss
But then I get
Warning (2): require(/scssphp/scss.inc.php): failed to open stream: No such file or directory [APP/Controller/AppController.php, line 84]
Warning (2): require(/scssphp/scss.inc.php) [<a href='https://secure.php.net/function.require'>function.require</a>]: failed to open stream: No such file or directory [APP/Controller/AppController.php, line 84]
Fatal error: require() [function.require]: Failed opening required '/scssphp/scss.inc.php' (include_path='.:/usr/local/lib/php') in /somepath/myapp.com/dev/src/Controller/AppController.php on line 84
Any help is greatly appreciated!
Update: this article describes how to include external classes quite well and helped me in a first step to solve the issue describe above: How can I use my own external class in CakePHP 3.0?
I'm getting the following error when trying to open the index file of a project that I am taking over on:
Warning: require_once(core_services/logging.php): failed to open stream: No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/app/docroot/www.website.com/index.php on line 7
Fatal error: require_once(): Failed opening required 'core_services/logging.php' (include_path='.:/Applications/XAMPP/xamppfiles/lib/php') in /Applications/XAMPP/xamppfiles/htdocs/app/docroot/www.website.com/index.php on line 7
The code the error refers to looks like this:
7 require_once "core_services/logging.php";
8 $logger=new syslog_class(__FILE__,LOG_DEBUG);
I checked to make sure the filepath exists by defining it and echoing it back as well as the contents of logging.phpin terminal and that returns just fine and when I get the current working directory on line 6, it returns /Applications/XAMPP/xamppfiles/htdocs/app/docroot/www.website.com, which I am assuming is defining my root folder.
Not sure exactly how to go about resolving this problem and if anyone has any ideas on approach, I would love to hear them as my PHP is a bit rusty and lacking outside of the context of wordpress.
edit: approaches I've tried so far
require 'core_services/logging.php';
require '/core_services/logging.php';
require './core_services/logging.php';
require '../core_services/logging.php';
require '/Applications/XAMPP/xamppfiles/htdocs/app/docroot/www.website.com/core_services/logging.php';
require realpath(dirname(__FILE__)) .'/core_services/logging.php';
require(__DIR__"/../core_services/logging.php");
require_once 'core_services/logging.php';
require_once '/core_services/logging.php';
require_once './core_services/logging.php';
require_once '../core_services/logging.php';
require_once '/Applications/XAMPP/xamppfiles/htdocs/app/docroot/www.website.com/core_services/logging.php';
require_once realpath(dirname(__FILE__)) .'/core_services/logging.php';
require_once __DIR__"/../core_services/logging.php";
I have also verified that it is not a permissions issue.
Try specifying full path:
require './core_services/logging.php';
//OR
require '/Applications/XAMPP/xamppfiles/htdocs/app/docroot/www.website.com/core_services/logging.php';
I am trying to make a login system for my app, and needed to use php for it. However I'm really new to php so I got errors. First of all, I am using a free web hosting for now, so it might be the issue here. That being said, here is the error part of my php:
<?php
require_once 'include/DB_Functions.php';
?>
And it gives me this error:
Warning: require_once(include/DB_Functions.php): failed to open stream: No such file or directory in /srv/disk3/1965965/www/yigittest.atwebpages.com/login.php on line 2
Fatal error: require_once(): Failed opening required 'include/DB_Functions.php' (include_path='.:/usr/local/php-5.4.45/share/pear') in /srv/disk3/1965965/www/yigittest.atwebpages.com/login.php on line 2
However, my include folder contains all the required php files. So what might be the issue here?
Try this demo code or plz share your folder structure
require_once(__DIR__.'/../include/DB_Functions.php');
I have been trying to import/include file in my php script file and somehow it is not working. I know this require_once question has been asked so many times [ 1. require_once with subfolders , 2. require_once() cant find the include path, 3. Using require_once for up directory not working] but none of them seemed to be working for me.
Blow picture will explain what I am trying to do clearly:
What I tried and errors:
Attempt 1
require_once(__DIR__.'GoogleClientApi/src/Google/Service/Analytics.php');
echo 'Hey1'; //Does not echo this, means something went wrong above.
require_once(__DIR__.'GoogleClientApi/src/Google/Client.php');
echo 'Hey2';
Error I get:
Attempt 2 (Fixed issue of attempt 1 but raised another issue.)
So I decided to use absolute path :
include '/Applications/MAMP/htdocs/GoogleClientApi/src/Google/Client.php';
echo 'Hey1';
include '/Applications/MAMP/htdocs/GoogleClientApi/src/Google/Service/Analytics.php';
echo 'Hey2';
Gives me error in Client.php file:
`Warning: require_once(/Google/Auth/AssertionCredentials.php): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/GoogleClientApi/src/Google/Client.php on line 18`
`Fatal error: require_once(): Failed opening required '/Google/Auth/AssertionCredentials.php' (include_path='.:/Applications/MAMP/bin/php/php5.5.10/lib/php') in /Applications/MAMP/htdocs/GoogleClientApi/src/Google/Client.php on line 18`
Investigating upon I found Client.php (of Google APIs Client Library for PHP) has these lines which are actually present:
require_once 'Google/Auth/AssertionCredentials.php'; // <-- Can't find
require_once 'Google/Cache/File.php'; // <-- Can't find
require_once 'Google/Cache/Memcache.php'; // <-- Can't find
I do not what is going wrong here. Fixed attempt 1's issue but now errors are in google's own library which I do not know how to overcome. I assume I am doing something silly which I can not figure out. Any help or suggestion will be appreciated.
Did you ever dumped __DIR__? Usually there's no / at the end. So you would have to change your code to this:
require_once(__DIR__.'/GoogleClientApi/src/Google/Service/Analytics.php');
^
I just checked in your screen shot with the error message, there's no / at the end.
/Applications/MAMP/htdocsGoogleClientApi/src/Google/Client.php
instead of /Applications/MAMP/htdocs/GoogleClientApi/src/Google/Client.php
It turns out I had to set the include path to include the root directory (src folder) using this line :
set_include_path("/Applications/MAMP/htdocs/GoogleClientApi/src/");
This worked for me in Client.php
set_include_path(__DIR__.'/../' . PATH_SEPARATOR . get_include_path());