Laravel 5 class - php

I installed laravel 5.1 on my windows 7, after that i tried to open blog/app/Htttp/routes.php.Now there's a error on my browser saying
"Fatal error: Class 'Route' not found in
C:\xampp\htdocs\Laravel_1\blog\app\Http\routes.php on line 14".
How do i remove this error?

Before a class is available in PHP you will need to require/include it. As you have opened up the file directly in the browser, the laravel application is not bootstrapped and none of the dependencies are loaded to be used.
If you open up public/index.php, you will find a line that says
require __DIR__.'/../bootstrap/autoload.php';
// this later calls composer autoload which compiles a file
// that includes all the classes that you have specified in your `composer.json`.
Now that you have opened the file directly, non of the classes are included and hence you get the error.
I am not sure about your intentions for opening that file directly in the browser. I can only suggest you that the error is expected and you should go through the public/index.php for the application to work properly.

Related

Class 'Google\Protobuf\Internal\Message' not found in "Message.proto"

I'm working on a project with protocol buffers and after i compiled a proto file, i cant seem to include it neither run it cos it keeps giving me this exact error:
PHP Fatal error: Class 'Google\Protobuf\Internal\Message' not found in /app/generated_files/message.php on line 13
On message.php i have the auto generated file from a .proto file and it includes Google\Protobuf\Internal\Message.
While reading on the protobuf github issues, i found that a person had the same problem where he concluded that it was the composer's fault. However in my case that wouldnt be the issue cos i didnt use composer.
I used pecl to install protocol buffers, and i have the library protobuf.so located in /etc/php5/apache2/XXXXXXXXX. I also added extension=protobuf.so on the last line of php.ini.
Keep in mind that im using docker for everything, therefore it might be something different but i still doubt.
In case anyone ends up here with the same question: you just need to add componser autoloader to your file include_once './vendor/autoload.php'; (change path as required)
I had the same problem, but the reason was different for me:
Git somehow messed up the casing of the folders, which lead to a wrong file path translation.
As soon as I fixed the casing ([...]/src/Google/Protobuf instead of [...]/src/google/protobuf in the vendor folder)

Undefined variable notice when trying to use Spotify API PHP Wrapper

I hope you are well. I am brand new to coding and have spent a lot of time trying to find a solution to my question, without much luck.
I was trying to utilize Spotify's API with PHP but ran into thus far unsurmountable hurdles. Please see steps taken below:
1.) I downloaded the Spotify PHP Wrapper library here https://github.com/jwilsson/spotify-web-api-php, and saved it in the same directory as my app. I then created a composer.json file as below :
{
"require": {
"jwilsson/spotify-web-api-php": "^1.0.0"
}
}
2.) After creating and saving the composer.json file, I ran "composer install" in terminal in the same directory as where the composer.json file was stored, which led to the creation of a composer.lock file and a vendor folder.
3.) I then moved the composer.lock, composer.json and vendor folders to my online hosting service (ecowebhosting) via firebug, so that I can run and test the code. I also created a .php file that I moved to the server as well.
In my .php page, i declared the required files as such (below) and ran a sample query form the Spotify API PHP Wrapper documentation on github, to confirm whether or not I successfully loaded the library (the autoload.php folder was automatically created in the "Vendor" folder, after I performed step 2 above):
require 'vendor/autoload.php';
$tracks = $api->getAlbumTracks('1oR3KrPIp4CbagPa3PhtPp');
print_r ($tracks);
When I run the code above, I get the error below:
Notice: Undefined variable: api in /home/sites/amanka.com/public_html/content/SmallApps/ListeningPod/home.php on line 8 Fatal error: Call to a member function getAlbumTracks() on a non-object in /home/sites/amanka.com/public_html/content/SmallApps/ListeningPod/home.php on line 8
This error causes me to think that I have not installed the Library correctly. Please any ideas where I might be going wrong?
Thanks a lot

Configuring TCPDF for use on local server with MAMP

I wish to use TCPDF so have downloaded the code and am having trouble using it.
I work on Mac locally using MAMP.
My project is stored in:
/Applications/MAMP/htdocs/my-project-title
I place the whole tcpdf folder in my project so it's location is:
/Applications/MAMP/htdocs/my-project-title/tcpdf
I found a file tcpdf_include.php in the examples directory so I pulled it out and placed it also in the tcpdf folder:
/Applications/MAMP/htdocs/my-project-title/tcpdf/tcpdf_include.php
So I wasn't sure if this was right but it seemed so. I then referenced tcpdf_include.php in my script: require_once('../tcpdf/tcpdf_include.php'); and it found the file all good.
Now I was confused as to how exactly this was working. I ran an example and got nothing and error log states:
[04-Nov-2015 16:27:36 Europe/Berlin] PHP Fatal error: Class 'TCPDF' not found in /Applications/MAMP/htdocs/my-project-title/scripts/myscript.php on line 15
... so it seems like it's just not running the script. I went to the config file to attempt to edit some stuff there.
I changed the following in the config file:
define ('K_PATH_MAIN', '/MAMP/htdocs/my-project-title/tcpdf/');
define ('K_PATH_URL', 'http://localhost:8888/my-project-title/tcpdf/');
These are now inline with how my project is set up. But I'm still getting the above error when I try to run the script.
What am I missing are there any examples of how to properly configure TCPDF?
Try this:
Store the script you are trying to run in /Applications/MAMP/htdocs/my-project-title, eg. /Applications/MAMP/htdocs/my-project-title/test.php
In that script, just do require_once('tcpdf/tcpdf.php'); (I'm assuming the tcpdf folder is still sitting here: /Applications/MAMP/htdocs/my-project-title/tcpdf)
You should then be able to instantiate an instance of the TCPDF class.
You shouldn't need to worry about anything else - it should just work. If it doesn't, try creating a fresh folder in your htdocs folder, drop a fresh copy of tcpdf in there and try again, just in case you've moved something in your current version that is messing things up.
To be clear, this is what test.php should contain:
require_once('tcpdf/tcpdf.php');
$pdf = new TCPDF();
Good luck!

Wrong __DIR__ magic constant value

I've been trying to install a web application which is built using the Laravel framework. The application is hosted as a GIT repository.
Here is a detailed description of my problem to clarify how I'm facing it.
For the first time I cloned the repository in the following path:
/var/www/app.example.com/script/
Then created a symbolic link to it's public directory like this to follow my server's nginx routing convention:
ln -s /var/www/app.example.com/script/public /var/www/app.example.com/public_html
But I decided to move everything out of the script directory to one upper level and this is where my problem started.
I moved the Laravel installation to /var/www/app.example.com/ and made nginx to directly load its public directory as the root path.
Now the problem is every time I try to load the application it's trying to read the files from their previous location:
Warning:
require(/var/www/app.example.com/script/public/../bootstrap/autoload.php):
failed to open stream: No such file or directory in
/var/www/app.example.com/public/index.php on line 21
Fatal error: require(): Failed opening required
'/var/www/app.example.com/script/public/../bootstrap/autoload.php'
(include_path='.:/usr/share/php:/usr/share/pear') in
/var/www/app.example.com/public/index.php on line 21
Notes to keep in mind:
I've used composer to install all the dependencies
curl -sS https://getcomposer.org/installer | php
php composer.phar install
I'm using nginx as my web server
I've tried removing everything (including ~/.composer) and start all over again to no avail.
I have even tried to move the whole project into a new root directory
It seems the problem is with __DIR__ magic constant since it contains the wrong path
Weirdly enough if I echo __DIR__ it prints the correct path but in the next line in which it's used it has the incorrect old path
I hope I have been clear enough in my description to avoid any confusion and possible down-votes.
So i could be completly wrong here, but is there a configuration file where it might have saved it? Or is there still something left in the script directory that can mabey cause this? As when the __DIR__ outputs the right value, then it should in the other code too.

Magento trying to autoload class unnecessarily

I'm using a 3rd party php library to connect to Microsoft Dynamics CRM, which I've placed in the /lib folder of Magento.
I've created a controller for testing purposes, in which I'm including the files from the lib folder (which are being included, as changing the paths throws an error), but when I try and initiate the class defined in one of the included files, i get this warning:
Warning: include(DynamicsCRM2011\Connector.php) [function.include]: failed to open stream: No such file or directory.
It shouldn't be trying to include anything, the class is already defined in a previously included file!
Any ideas how I can prevent this from happening? I'd have thought it would only try to autoload the file if the class is undefined surely?

Categories