我的网站在localhost中工作,我已将我的网站配置为prod并将文件放在服务器上,当我访问该网站时:http://tolkienbestiaire.esy.es/web/tolkien
我有一个错误:
Unable to find template "TolkienBestiaireBundle:Bestiaire:index.html.twig" (looked into: /home/u493202215/public_html/app/Resources/views, /home/u493202215/public_html/vendor/symfony/symfony/src/Symfony/Bridge/Twig/Resources/views/Form).
我不明白为什么会在" app/Resources/views
"因为真正的方式是../public_html/src/Tolkien/BestiaireBundle/Resources/views
。
当我转到 http://tolkienbestiaire.esy.es/web/login
时,错误:
Warning: file_get_contents(C:\wamp64\www\tolkien-bestiaire\app/Resources/FOSUserBundle/views/Security/login.html.twig): failed to open stream: No such file or directory
但 C:\wamp64\www\tolkien-bestiaire\...
是我的本地目录,服务器目录是public_html。
我在Windows上工作,是一个unix服务器。
答案 0 :(得分:0)
是的,那么如果它有效,你的路由很好......
您可以编辑和删除从/web
复制的代码文件
当我说你的虚拟主机配置
我正在为您的网站引用apache2配置文件 (例如:http://symfony.com/doc/current/setup/web_server_configuration.html)
你的似乎不完整
如果您想在不清除缓存的情况下查看工作结果,则必须通过app_dev.php文件(http://tolkienbestiaire.esy.es/app_dev.php)
但是,该链接仅在更正虚拟主机后才有效。
答案 1 :(得分:0)
我编辑了我的答案。
虚拟主机:
<VirtualHost *:80>
ServerName localhost
DocumentRoot c:/wamp64/www
<Directory "c:/wamp64/www/">
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName virtual-host-tolkien-bestiaire
DocumentRoot c:/wamp64/www/tolkien-bestiaire
<Directory "c:/wamp64/www/tolkien-bestiaire/">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
答案 2 :(得分:0)
我跳过了,你会看看我给你的Symfonny文档的链接,找到你做错了什么......
您的虚拟主机指向c:/wamp64/www/tolkien-bestiaire/
而不是c:/wamp64/www/tolkien-bestiaire/web/
此外,如果c:/wamp64/www/tolkien-bestiaire
是symfony项目的目录,则不需要在同一文件中使用第一个vhost。
首先建议每个文件只有一个vhost。
Symfony doc(http://symfony.com/doc/current/setup/web_server_configuration.html)的第二个例子是Symfony的一个很好的vhost文件例子。
我建议您运行终端并重新编写重写模块a2enmod rewrite
这样做可以通过此链接http://tolkienbestiaire.esy.es转到您的网站,而不是您之前提供的链接。
希望它能帮助你解决vhost问题。
答案 3 :(得分:-1)
我清空了缓存,现在我们可以转到http://tolkienbestiaire.esy.es/web/login,http://tolkienbestiaire.esy.es/web/register和http://tolkienbestiaire.esy.es/web/about,关于另一个捆绑(
的src
| -Tolkien
| | -BestiaireBundle(http://tolkienbestiaire.esy.es/web/tolkien,主页等...)
| | -CoreBundle(http://tolkienbestiaire.esy.es/web/about和主要布局 )
app / config / routing.yml:
tolkien_cms:
resource: "@TolkienCmsBundle/Controller/"
type: annotation
prefix: /
tolkien_bestiaire:
resource: "@TolkienBestiaireBundle/Resources/config/routing.yml"
prefix: /tolkien
tolkien_core:
resource: "@TolkienCoreBundle/Resources/config/routing.yml"
fos_user_security:
resource: "@FOSUserBundle/Resources/config/routing/security.xml"
fos_user_profile:
resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
prefix: /profile
fos_user_register:
resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
prefix: /register
fos_user_resetting:
resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
prefix: /resetting
fos_user_change_password:
resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
prefix: /profile
src / Tolkien / BestiaireBundle / BestiaireController.php:
<?php
namespace Tolkien\BestiaireBundle\Controller;
use Symfony\Component\Yaml\Tests\A;
use Tolkien\BestiaireBundle\Entity\Bestiaire;
use Tolkien\BestiaireBundle\Event\MessagePostEvent;
use Tolkien\BestiaireBundle\Event\TolkienEvents;
use Tolkien\BestiaireBundle\Form\BestiaireEditType;
use Tolkien\BestiaireBundle\Form\BestiaireType;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class BestiaireController extends Controller
{
public function indexAction($page)
{
$nbPerPage = 5;
$listBestiaires = $this->getDoctrine()
->getManager()
->getRepository('TolkienBestiaireBundle:Bestiaire')
->findAll();
$nbPages = ceil(count($listBestiaires) / $nbPerPage);
return $this->render('TolkienBestiaireBundle:Bestiaire:index.html.twig', array(
'listBestiaires' => $listBestiaires,
'nbPages' => $nbPages,
'page' => $page,
));
}
public function bestiaireAction()
{
$listBestiaires = $this->getDoctrine()
->getManager()
->getRepository('TolkienBestiaireBundle:Bestiaire')
->findAll();
return $this->render('TolkienBestiaireBundle:Bestiaire:bestiaire.html.twig', array(
'listBestiaires' => $listBestiaires
));
}
public function viewAction(Bestiaire $bestiaire)
{
$em = $this->getDoctrine()->getManager();
$listApplications = $em
->getRepository('TolkienBestiaireBundle:Application')
->findBy(array('bestiaire' => $bestiaire));
return $this->render('TolkienBestiaireBundle:Bestiaire:view.html.twig', array(
'bestiaire' => $bestiaire,
'listApplications' => $listApplications,
));
}
/**
* @Security("has_role('ROLE_AUTEUR') or has_role('ROLE_USER') or has_role('ROLE_ADMIN') ")
*/
public function addAction(Request $request)
{
$bestiaire = new Bestiaire();
$form = $this->get('form.factory')->create(BestiaireType::class, $bestiaire);
if ($request->isMethod('POST') && $form->handleRequest($request)->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($bestiaire);
$em->flush();
$request->getSession()->getFlashBag()->add('notice', 'Annonce bien enregistrée.');
return $this->redirectToRoute('tolkien_bestiaire_view', array('id' => $bestiaire->getId()));
}
return $this->render('TolkienBestiaireBundle:Bestiaire:add.html.twig', array(
'form' => $form->createView(),
));
}
/**
* @Security("has_role('ROLE_AUTEUR') or has_role('ROLE_USER') or has_role('ROLE_ADMIN') ")
*/
public function editAction($id, Request $request)
{
$em = $this->getDoctrine()->getManager();
$bestiaire = $em->getRepository('TolkienBestiaireBundle:Bestiaire')->find($id);
if (null === $bestiaire) {
throw new NotFoundHttpException("L'annonce d'id ".$id." n'existe pas.");
}
$form = $this->get('form.factory')->create(BestiaireEditType::class, $bestiaire);
if ($request->isMethod('POST') && $form->handleRequest($request)->isValid()) {
$em->flush();
$request->getSession()->getFlashBag()->add('notice', 'Annonce bien modifiée.');
return $this->redirectToRoute('tolkien_bestiaire_view', array('id' => $bestiaire->getId()));
}
return $this->render('TolkienBestiaireBundle:Bestiaire:edit.html.twig', array(
'bestiaire' => $bestiaire,
'form' => $form->createView(),
));
}
/**
* @Security("has_role('ROLE_ADMIN')")
*/
public function deleteAction(Request $request, Bestiaire $bestiaire)
{
$em = $this->getDoctrine()->getManager();
$form = $this->get('form.factory')->create();
if($request->isMethod('POST') && $form->handleRequest($request)->isValid())
{
$em->remove($bestiaire);
$em->flush();
$request->getSession()->getFlashBag()->add('info', "L'annonce a bien été suprimée.");
return $this->redirectToRoute('tolkien_bestiaire_home');
}
return $this->render('TolkienBestiaireBundle:Bestiaire:delete.html.twig', array(
'bestiaire' => $bestiaire,
'form' => $form->createView()
));
}
public function menuAction($limit)
{
$em = $this->getDoctrine()->getManager();
$listBestiaires = $em->getRepository('TolkienBestiaireBundle:Bestiaire')->findBy(
array(),
array('date' => 'desc'),
$limit,
0
);
return $this->render('TolkienBestiaireBundle:Bestiaire:menu.html.twig', array(
'listBestiaires' => $listBestiaires
));
}
public function translationAction($name)
{
return $this->render('TolkienBestiaireBundle:Bestiaire:translation.html.twig', array(
'name' => $name
));
}
/**
* @ParamConverter("json")
*/
public function ParamConverterAction($json)
{
return new Response(print_r($json, true));
}
public function searchAction($name, Request $request)
{
$em = $this->getDoctrine()->getManager();
$query = $this->getRequest()->get('query');
if (!$query)
{
if(!$request->isXmlHttpRequest()){
return $this->redirect($this->generateUrl('tolkien_bestiaire'));
} else {
return new Response('No results.');
}
}
$bestiaire = $em->getRepository('TolkienBestiaireBundle:Bestiaire')->find($name);
if($request->isXmlHttpRequest()) {
if('*' == $query || !$bestiaire || $query == '') {
return new Response('No results.');
}
return $this->render('TolkienBestiaireBundle:Bestiaire:index.html.twig', array('bestiaire' => $bestiaire));
}
return $this->render('TolkienBestiaireBundle:Bestiaire:search.html.twig', array(
'bestiaire' => $bestiaire
));
}
public function testSearch()
{
$client = static::createClient();
$crawler = $client->request('GET', '/bestiaire/search');
$this->assertEquals('Tolkien\BestiaireBundle\Controller\BestiaireController::searchAction', $client->getRequest()->attributes->get('_controller'));
$crawler = $client->request('GET', '/bestiaire/search?query=sens*', array(), array(), array(
'X-Requested-With' => 'XMLHttpRequest',
));
$this->assertTrue($crawler->filter('tr')->count()== 2);
}
public function updateDataAction(Request $request)
{
$data = $request->get('input');
$em = $this->getDoctrine()->getManager();
$query = $em->createQuery(''
. 'SELECT c.id, c.name '
. 'FROM TolkienBestiaireBundle:Bestiaire c '
. 'WHERE c.name LIKE :data '
. 'ORDER BY c.name ASC'
)
->setParameter('data', '%' . $data . '%');
$results = $query->getResult();
$bestiaireList = '<ul id="matchList">';
foreach ($results as $result) {
$matchStringBold = preg_replace('/('.$data.')/i', '<strong>$1</strong>', $result['name']); // Replace text field input by bold one
$bestiaireList .= '<li id="'.$result['name'].'">'.$matchStringBold.'</li>'; // Create the matching list - we put maching name in the ID too
}
$bestiaireList .= '</ul>';
$response = new JsonResponse();
$response->setData(array('countryList' => $bestiaireList));
return $response;
}
}
src / Tolkien / BestiaireBundle / Resources / config / routing.yml:
tolkien_bestiaire_home:
path: /{page}
defaults:
_controller: TolkienBestiaireBundle:Bestiaire:index
page: 1
requirements:
page: \d*
tolkien_bestiaire_bestiaire:
path: /bestiaire
defaults:
_controller: TolkienBestiaireBundle:Bestiaire:bestiaire
tolkien_bestiaire_view:
path: /bestiaire/{id}
defaults:
_controller: TolkienBestiaireBundle:Bestiaire:view
requirements:
id: \d+
tolkien_bestiaire_add:
path: /add
defaults:
_controller: TolkienBestiaireBundle:Bestiaire:add
tolkien_bestiaire_edit:
path: /edit/{id}
defaults:
_controller: TolkienBestiaireBundle:Bestiaire:edit
requirements:
id: \d+
tolkien_bestiaire_delete:
path: /delete/{id}
defaults:
_controller: TolkienBestiaireBundle:Bestiaire:delete
requirements:
id: \d+
tolkien_bestiaire_paramconverter:
path: /test/{json}
defaults:
_controller: "TolkienBestiaireBundle:Bestiaire:ParamConverter"
tolkien_bestiaire_search:
path: /
defaults:
_controller: "TolkienBestiaireBundle:Bestiaire:search"
tuto_autocomplete:
path: /autocomplete
defaults: { _controller: Sim100TutoBundle:Autocomplete:index }
ajax_autocomplete_countries:
path: /ajax/autocomplete/update/data
defaults: { _controller: Sim100TutoBundle:AjaxAutocomplete:updateData }
虚拟主机:
<VirtualHost *:80>
ServerName localhost
DocumentRoot c:/wamp64/www
<Directory "c:/wamp64/www/">
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName virtual-host-tolkien-bestiaire
DocumentRoot c:/wamp64/www/tolkien-bestiaire
<Directory "c:/wamp64/www/tolkien-bestiaire/">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>