リンクをクリックすると、所有しているMyAlbumControllerにオブジェクトIDを渡します。
<?php
namespace YM\TestBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
class AlbumController extends Controller
{
public function deleteAction($id)
{
if ($id > 0) {
// We get the EntityManager
$em = $this->getDoctrine()
->getEntityManager();
// We get the Entity that matches id: $id
$article = $em->getRepository('YMTestBundle:Album')
->find($id);
// If the Album doesn't exist, we throw out a 404 error
if ($article == null) {
throw $this->createNotFoundException('Album[id='.$id.'] do not exist');
}
// We delete the article
$em->remove($article);
$em->flush();
$this->get('session')->getFlashBag()->add('info', 'Album deleted successfully');
// Puis on redirige vers l'accueil
return $this->redirect( $this->generateUrl('ymtest_Artist') );
}
return $this->redirect( $this->generateUrl('ymtest_dashboard') );
}
}
そしてそれは動作します。
しかし、stackoverflowで何かが見られます。そこでは、再現したいオブジェクト(S2がそれ自体を見つけることができると聞きました)を渡します。
<?php
namespace YM\TestBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
class AlbumController extends Controller
{
public function deleteAction(Album $album)
{
// We get the EntityManager
$em = $this->getDoctrine()
->getEntityManager();
// If the Album doesn't exist, we throw out a 404 error
if ($lbum == null) {
throw $this->createNotFoundException('Album[id='.$id.'] do not exist');
}
// We delete the article
$em->remove($album);
$em->flush();
$this->get('session')->getFlashBag()->add('info', 'Album deleted successfully');
// Puis on redirige vers l'accueil
return $this->redirect( $this->generateUrl('ymtest_Artist') );
return $this->redirect( $this->generateUrl('ymtest_dashboard') );
}
}
しかし、それは機能しません、私は持っています:
クラスYM\TestBundle \ Controller\Albumが存在しません
なんで ?どうも