Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7550161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:08:32+00:00 2026-05-30T10:08:32+00:00

I am getting started with Symfony 2 & I am following this tutorial. Now,

  • 0

I am getting started with Symfony 2 & I am following this tutorial. Now, this tutorial is easy & I was able to follow it completely. This is the code in my Controller

<?php
namespace DemoCompany\HelloBundle\Controller;

use Symfony\Component\HttpFoundation\Response;

class HelloController{
    public function indexAction($name){
        return new Response('<h1>hello ' . ucfirst($name) . '</h1>');
    }
}

Now, I have some questions

  1. When I run the code without including namespace DemoCompany\HelloBundle\Controller;, it gives me an error. But it does work fine when this line is included; so I want to know: Why does it work with namespace statement & why doesn’t it work without namespace. Please clarify.

  2. Follow up question: I am returning a new Response object but it is neither being defined, nor is my class HelloController extending some baseclass (which may have this response object defined). So the question is: How is PHP able to find & then load this file?

  3. In Symfony, do custom controllers/models/views need to extend some base class? For example, in Codeigniter, we have to do something like class Blog extends CI_Controller, so that all the methods defined in CI_Controller would be available in current scope using $this. Does Symfony have the same practice or does it do something different?

  4. Since this controller is namespaced to DemoCompany\HelloBundle\Controller, how come normal PHP functions work without a backslash?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T10:08:33+00:00Added an answer on May 30, 2026 at 10:08 am

    I’ve only very briefly used Symfony2, here are my answers though:

    1) That’ll be because Symfony needs your Controller to exist in the DemoCompany\HelloBundle\Controller namespace for autoloading

    2) At use Symfony\Component\HttpFoundation\Response;, you’re telling PHP to look in there if the method can’t be found locally

    3) Don’t know on that one…

    4) Built-in PHP functions aren’t in any specific namespace (namespaces are new to PHP), so work anywhere

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

yikes i have forgotten but am following: http://www.symfony-project.org/getting-started/1_4/en/03-Symfony-Installation i have a jobeet directory and
I am just getting started with wxPython. I have the following code: import wx
I'm just getting started with Threads in Java so this might be a basic
I'm new to .net mvc 3. I was using PHP Symfony previously. In this
I am just getting started with symfony and am trying to build the database
I configured my /etc/apache/httpd.conf as said in the getting started tutorial : # Be
Just getting started with XPath, and using it's implementation with PHP's SimpleXML objects. Right
Just getting started with Obj-C and iOS programming. I have some code that loads
Im just getting started on this whole WPF thing, and need to understand some
While getting started with some VS2005-generated MFC code, I noticed it overrode a method

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.