我清空缓存,现在我们可以去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,主布局 )
应用/配置/ 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 /托尔金/ 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 /托尔金/ BestiaireBundle /资源/配置/ 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>