Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialRutvij Kanzaria
19,624 Pointshtaccess file in xampp
I created index.php page with the following code:
<?php require '/vendor/autoload.php'; $app = new \Slim\Slim(); $app->get('/hello/:name', function ($name) { echo "Hello, " . $name; }); $app->run(); ?>
I am using xampp server but when I run the file, it is showing 404 error. I also used the htaccess code shown in the video but can't find the fix. Need a Help!
Rutvij Kanzaria
19,624 PointsI have tried this earlier. I am following the steps shown in the Hampton's video.
- First I created .json file.
- Then, I installed monolog/monolog
- After installing slim, when I use $app->run(); it is throwing the 404 error
- Since I cannot create .htaccess file from txt file, I copied the file that was in \Slim\Slim.htaccess and pasted it in htdocs where I have my index.php
Basically, routing is not working in my case I guess
Bruno Silva
Courses Plus Student 3,227 Pointstry this then
require('/vendor/autoload.php');
Note: I added (...) to your code
Rutvij Kanzaria
19,624 PointsStill having the same problem
Bruno Silva
Courses Plus Student 3,227 PointsIn your result page, check the element inspector for errors. ( CTRL + Shift + I )
See if in the network the connection to your index.php is established and the erros in the console.
Past here the errors after please.
Rutvij Kanzaria
19,624 PointsNo, The connection ain't established. If I echo any statement without using Slim commands, then I can get the output. But if I use following code, then it ain't working
<?php
require('/vendor/autoload.php');
$app = new \Slim\Slim();
$app->get('/hello/:name', function ($name) {
echo "Hello, " . $name;
});
$app->run();
If I use the following code then it is working
<?php
require '/vendor/autoload.php';
echo "Hello World!";
?>
Bruno Silva
Courses Plus Student 3,227 PointsLet's try this. On the console, see how many works you've received.
However, I think that the problem is the syntax in new\Slim\Slim();
Try this first:
$app = new slim slim();
If it now work, do the following in order to get more information
<?php
require('/vendor/autoload.php');
console.log("work-1");
$app = new \Slim\Slim();
console.log("work-2");
$app->get('/hello/:name', function ($name) {
console.log("work-3");
echo "Hello, " . $name;
console.log("work-4");
});
$app->run();
console.log("work-5");
?>
Rutvij Kanzaria
19,624 PointsNo it ain't working yet. I think the problem is in creating the htaccess file. It can't link the slim library files and hence it is not establishing connection.
Bruno Silva
Courses Plus Student 3,227 PointsI've read some docs ( http://docs.slimframework.com/ ) and have you instaled Slim like it is in the instructions ( via composer )?
If you have, i can only assume that the problem is in the autoload.php file. ( See if the path is correct... try putting all the path, from the beggining to the end e.g.: C:\.....\autoload.php )
Rutvij Kanzaria
19,624 PointsYes I have installed slim framework using composer. Also, autoload.php is working because when I put log files, it is displaying. I cannot figure out the problem
Rutvij Kanzaria
19,624 PointsThanks a lot @Bruno. I have figured it out and it is all working fine now
Bruno Silva
Courses Plus Student 3,227 PointsI was going to instaled and test by myself to try a thing.
So, what was the solution?
Rutvij Kanzaria
19,624 PointsIt will sound funny but I put the .htaccess file in vendor folder. On changing the file location to index.php location, It started working
Bruno Silva
Courses Plus Student 3,227 PointsI thought that they were together.
Still, it's ok. Every programer have already had this type of problem.
Continue the good work!
Rutvij Kanzaria
19,624 PointsYeah Thank You. I just have one more doubt. Is the content of every .htaccess file same for every project?
Bruno Silva
Courses Plus Student 3,227 PointsI think so. You can change it but you shouln't. Read more about it in those two posts:
https://www.digitalocean.com/community/tutorials/how-to-use-the-htaccess-file http://www.htmlgoodies.com/beyond/webmaster/article.php/3899416
Bruno Silva
Courses Plus Student 3,227 PointsBruno Silva
Courses Plus Student 3,227 PointsAre you running apache? And is your index.php page in htdocs files?
You're solution is probably like this one:
https://teamtreehouse.com/forum/i-cant-access-my-local-host
Check it and tell me if this solution worked.