Reputation: 1466
I got a hard time learning Symfony 2.8
.
I have created a bundle
called BlogBudle
and inside this I created a controller
called HomeController
.
My goal is:
Create a /test
URL
and assign it to home page url
Below is my code:
/var/www/symfony/app/config/routing.yml
blog:
resource: "@BlogBundle/Controller/"
type: annotation
prefix: /
app:
resource: "@AppBundle/Controller/"
type: annotation
/var/www/symfony/src/BlogBundle/Controller/HomeController.php
namespace BlogBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
class HomeController extends Controller
{
/**
* @Route("/test")
*/
public function indexAction()
{
return $this->render('BlogBundle:Default:index.html.twig');
}
}
When I run php app/console debug:router
, it shows
Name Method Scheme Host Path
blog_home_index ANY ANY ANY /test
Problem:
If I visit http://www.example.com/test
, it's showing 404
error.
Also below is my VH Configuration:
<VirtualHost *:80>
#ServerAdmin [email protected]
ServerName mysmfony.com
ServerAlias www.mysymfony.com
DocumentRoot /var/www/symfony/web
DirectoryIndex app_dev.php
<Directory /var/www/symfony/web>
AllowOverride All
Options All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/mysymfony.com.log
CustomLog ${APACHE_LOG_DIR}/mysymfony.com.log combined
</VirtualHost>
Upvotes: 1
Views: 14077
Reputation: 485
Need to overwrite your bundle route in app/config/routing.yml such as :
user_test:
resource: "@BlogBundle/Resources/config/routing.yml"
prefix: /
and
Here is route for redirect to your Home page
BlogBundle/Resources/config/routing.yml
any_unique_route_name:
pattern: /test
defaults: { _controller: BlogBundle:Home:index }
Make sure this is helpful to you.
Upvotes: 2
Reputation: 717
Here is an example :
routing.yml
my_route_name:
path: /test
defaults:
_controller: NamespaceBlogBundle:Home:index
Also if your controller is called HomeController render should be like this
public function indexAction()
{
return $this->render('NamespaceBlogBundle:Home:index.html.twig');
}
Upvotes: 0