我正在学习 Symfony 框架,但在让它返回正确的 URL 到资源时遇到了问题。我在 src/Company/TestBundle/Controller/DefaultController.php 文件中创建了一个新包 Company/TestBundle:
<?php
namespace Company\TestBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class DefaultController extends Controller
{
public function indexAction()
{
return $this->render('TestBundle:Default:index.html.twig');
}
}
在 src/Company/TestBundle/Resources/views/Default/index.html.twig 中:
{% extends "SmallworldBundle:Default:main.html.twig" %}
{%block title %}It's a small world after all!{% endblock %}
{% block body %} It's a small world! {% endblock %}
在 src/Company/TestBundle/Resources/views/Default/main.html.twig 中:
<html>
<head>
{% block stylesheets %}
<link rel = "stylesheet" href = "{{ asset('css/small.css') }}" type = "text/css" />
{% endblock %}
<title>{% block title %} {% endblock %}</title>
</head>
<body>
{%block body %}{% endblock %}
</body>
</html>
现在,我已经运行了 php app/console assets:install --symlink 但即便如此,生成的代码仍试图链接到“/css/small.css”而不是文件的实际位置,即 src/Company/ TestBundle/Resources/public/css/small.css
有人可以解释为什么这没有链接到正确的位置吗?