Support the ongoing development of Laravel.io →
Configuration Views Blade
Last updated 2 years ago.
0

The first thing concerns me where you state that the code only shows. This makes me think that you need to make sure your php module is being loaded in your httpd file... check this first before anything.

Next, your

Route::controller();

is missing an argument, you would need to include the name of the controller

Route::controller('<route>', '<name of restful controller>');

The url you are accessing this route by does not need to specify the 'index.php' file. When you call a route, let's say '/admin', the index file is already called for you, and your logic in the route controller should display the correct view when you call it either a method in your controller (url would be: http://localhost/testlaravel/public/admin, assuming testlaravel is the root of the laravel project):

function showIndex()
{
    return View::make('admin');
}

or from your route directly (not best practice):

Route::get('/admin', function()
{
     return View::make('admin');
});

Lastly, the httpd.conf looks fine to me.

Last updated 2 years ago.
0

Do you have short tags enabled in your php config? I'm seeing that your controller's source code is opened with <? instead of <?php.

Last updated 2 years ago.
0

Your view file should be user.blade.php not just user.php

Last updated 2 years ago.
0

Thanks for your feedback.

I made three changes:

  1. Routes.php : Changed route definition for TestController
<?php

Route::get('/', function()
{
	return View::make('hello');
});

Route::get('/users', function()
{
	$users = User::all();
	//var_dump($users);
    return View::make('users')->with('users', $users);	
});

Route::controller('/test','TestController');
?>
  1. Changed view from users.php to users.blade.php. It does not contain php opening and closing tags <?php and ?>
@extends('layout')

@section('content')
    @foreach($users as $user)
        <p>{{ $user->name }}</p>
    @endforeach
@stop
  1. Added <?php opening tag to TestController
<?php
class TestController extends BaseController {

    /**
     * Show the profile for the given user.
     */
    public function test()
    {
        return 'Hello World';
    }
}
?>

I am accessing users and test functions at

http://localhost/testlaravel/public/test
http://localhost/testlaravel/public/users

Still I am getting following response in both cases:


<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <meta name="robots" content="noindex,nofollow" />
        <style>
            /* Copyright (c) 2010, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: http://developer.yahoo.com/yui/license.html */
            html{color:#000;background:#FFF;}body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blockquote,th,td{margin:0;padding:0;}table{border-collapse:collapse;border-spacing:0;}fieldset,img{border:0;}address,caption,cite,code,dfn,em,strong,th,var{font-style:normal;font-weight:normal;}li{list-style:none;}caption,th{text-align:left;}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal;}q:before,q:after{content:'';}abbr,acronym{border:0;font-variant:normal;}sup{vertical-align:text-top;}sub{vertical-align:text-bottom;}input,textarea,select{font-family:inherit;font-size:inherit;font-weight:inherit;}input,textarea,select{*font-size:100%;}legend{color:#000;}

            html { background: #eee; padding: 10px }
            img { border: 0; }
            #sf-resetcontent { width:970px; margin:0 auto; }
                        .sf-reset { font: 11px Verdana, Arial, sans-serif; color: #333 }
            .sf-reset .clear { clear:both; height:0; font-size:0; line-height:0; }
            .sf-reset .clear_fix:after { display:block; height:0; clear:both; visibility:hidden; }
            .sf-reset .clear_fix { display:inline-block; }
            .sf-reset * html .clear_fix { height:1%; }
            .sf-reset .clear_fix { display:block; }
            .sf-reset, .sf-reset .block { margin: auto }
            .sf-reset abbr { border-bottom: 1px dotted #000; cursor: help; }
            .sf-reset p { font-size:14px; line-height:20px; color:#868686; padding-bottom:20px }
            .sf-reset strong { font-weight:bold; }
            .sf-reset a { color:#6c6159; }
            .sf-reset a img { border:none; }
            .sf-reset a:hover { text-decoration:underline; }
            .sf-reset em { font-style:italic; }
            .sf-reset h1, .sf-reset h2 { font: 20px Georgia, "Times New Roman", Times, serif }
            .sf-reset h2 span { background-color: #fff; color: #333; padding: 6px; float: left; margin-right: 10px; }
            .sf-reset .traces li { font-size:12px; padding: 2px 4px; list-style-type:decimal; margin-left:20px; }
            .sf-reset .block { background-color:#FFFFFF; padding:10px 28px; margin-bottom:20px;
                -webkit-border-bottom-right-radius: 16px;
                -webkit-border-bottom-left-radius: 16px;
                -moz-border-radius-bottomright: 16px;
                -moz-border-radius-bottomleft: 16px;
                border-bottom-right-radius: 16px;
                border-bottom-left-radius: 16px;
                border-bottom:1px solid #ccc;
                border-right:1px solid #ccc;
                border-left:1px solid #ccc;
            }
            .sf-reset .block_exception { background-color:#ddd; color: #333; padding:20px;
                -webkit-border-top-left-radius: 16px;
                -webkit-border-top-right-radius: 16px;
                -moz-border-radius-topleft: 16px;
                -moz-border-radius-topright: 16px;
                border-top-left-radius: 16px;
                border-top-right-radius: 16px;
                border-top:1px solid #ccc;
                border-right:1px solid #ccc;
                border-left:1px solid #ccc;
                overflow: hidden;
                word-wrap: break-word;
            }
            .sf-reset li a { background:none; color:#868686; text-decoration:none; }
            .sf-reset li a:hover { background:none; color:#313131; text-decoration:underline; }
            .sf-reset ol { padding: 10px 0; }
            .sf-reset h1 { background-color:#FFFFFF; padding: 15px 28px; margin-bottom: 20px;
                -webkit-border-radius: 10px;
                -moz-border-radius: 10px;
                border-radius: 10px;
                border: 1px solid #ccc;
            }
        </style>
    </head>
    <body>
                    <div id="sf-resetcontent" class="sf-reset">
                <h1>Whoops, looks like something went wrong.</h1>

            </div>
    </body>
</html>

When I try http://localhost/testlaravel/public, I get correct hello.php rendered with message "You have arrived". That means php is getting loaded properly in httpd.config.

Regards, Suraj

Last updated 2 years ago.
0

I see that you have a controller for the route '/test' but not a route for '/test' ; and no controller for '/users' route

Consider this format and structure:

Route::controller('/test', 'TestController');

Route::get('/test', 'TestController@getIndex');

Let's create this 'TestController' with the example method:

class TestController extends \Basecontroller {
      public function getIndex()
      {
           return View::make('test');
      }
      public function postIndex()
      {
            //store data in db
       }
}

Laravel will now reference the specified method inside of the controller. Using the controller method allows you to create custom methods/pages. Laravel looks for them when you prepend the method/page name with a HTTP verb.

These verbs include: GET and POST, as opposed to a resource controller that uses basic CRUD operations, and uses the verbs: GET, POST, PUT, and DELETE.

The postIndex() method would then logically handle any post data that comes from 'getIndex()', for example you would set this up in your routes.php by writing:

Route::post('/test', 'TestController@postIndex');

Any post originating from getIndex() will then be processed by 'postIndex()' method. You could store data to your database here, or echo back new information to the 'test' view.

Let me know if this helps.

Last updated 2 years ago.
0

Thanks. The '/test' route issue solved after adding Route::get('/test', 'TestController@getIndex') to routes.php

For /users, I have followed QuickStart tutorial as is. It does not mention to create a controller for /users.

However, when I try http://localhost/testlaravel/public/users, I got code of views/layout.php displayed on browser.

I renamed layout.php to layout.blade.php and it displayed the user names from database correctly.

Thanks again.

Last updated 2 years ago.
0

No problem!

Happy coding.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.