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 trial

PHP Building Websites with PHP Slim Basics & Twig Templates Routing For Our Project

Minh Duong
Minh Duong
1,606 Points

I can't access the contact page. However, I can create the $app->get('/', function(){...}); and it work

here is my code

<?php
/**
 * Created by PhpStorm.
 * User: minh
 * Date: 6/27/2015
 * Time: 10:16 AM
 */
require 'vendor/autoload.php';

date_default_timezone_set('Europe/London');

// use Monolog\Logger; // use Monolog\Handler\StreamHandler;

$app = new \Slim\Slim();

$app->get('/', function() { echo 'Hello, this is the home page.'; });

$app->get('/contact', function() { echo 'Feel free to contact us.'; });

$app->run();

I did create the .htaccess file

When i run my program it work for this

http://localhost:63342/test/testCase.php and I see the 'Hello, this is the home page'

but when I do

http://localhost:63342/test/testCase.php/contact

it fail and "404 Not Found

PhpStorm 8.0.3 "

3 Answers

I think your rule is wrong. You have http://localhost:63342/test/testCase.php/contact

I think it should be http://localhost:63342/test/contact

I have the same problem with this build. You can see it live at http://vets rights.org. The nav is wrong if you start at http://vets rights.org/index.php

I have to write a a rule to actually return without index.php.

Minh Duong
Minh Duong
1,606 Points

What do you mean when you said "your rule is wrong http://localhost:63342/test/testCase.php/contact"

I run the code in phpStorm and it give me the address like http://localhost:63342/test/testCase.php/contact

How do you make it like http://localhost:63342/test/contact

Can you explain with more details for me ? I can't get around with this

How do you run this http://vets rights.org. instead of this http://vets rights.org/index.php

my .htaccess look like this

RewriteEngine On

Some hosts may require you to use the RewriteBase directive.

If you need to use the RewriteBase directive, it should be the

absolute physical path to the directory that contains this htaccess file.

RewriteBase /

RewriteBase /~mcd4874/ RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [QSA,L]

sorry, I was on my iPad and it auto corrected url to rule.

Try removing testCase.php from the contact page url and see if you get your contact page.

Andreas Bom
Andreas Bom
3,441 Points

I have a simular problem.

The url http://127.0.0.1/TestingRouting/ is working, and I get "Hello, this is the home page". But http://127.0.0.1/TestingRouting/contact is not working. If I instead use http://127.0.0.1/TestingRouting/index.php/contact I get the contact message

here's someone else with the same problem. http://stackoverflow.com/questions/11569445/how-do-i-get-slim-framework-to-work-without-having-to-put-index-php-in-the-url

However, I don't quite understand how to fix it.

I had the same problem. I think the issue was in the main.twig template as far as what the link was. I will have to check later though.