情况
我目前正在 Symfony 3 中制作 CMS,我已经自学了使用 Symfony 的工作,但我遇到了一个我似乎无法找到问题的问题。
环境
应用的完整环境如下:
源代码: - AuthBundle - 控制器 - 默认控制器.php - 安全控制器.php - 资源 - 配置 - 服务.yml - 意见 - 默认 - index.html.twig - 安全 - login.html.twig - AuthBundle.php - 核心捆绑 - 控制器 - 默认控制器.php - 实体 - 专辑.php - Bargroep.php - BargroepenRepository.php - Barpersoneel.php - BarpersoneelRepository.php - 轮播.php - 数据.php - EvPkmn.php - 事件.php - 图像.php - Inschrijvingen.php - 日志.php - Maillijst.php - Post.php - 用户.php - UserRepository.php - 变量.php - 投票.php - 形式 - 专辑类型.php - 事件类型.php - ImageType.php - MailLijstType.php - PostType.php - 用户类型.php - 存储库 - MaiLIjstRepository.php - 资源 - 配置 - 路由.yml - 服务.yml - 意见 - 默认 - index.html.twig - CoreBundle.php - 事件捆绑 - 控制器 - 默认控制器.php - 资源 - 配置 - 服务.yml - 意见 - 行政 - event.html.twig - events.html.twig - index.html.twig - 默认 - event.html.twig - events.html.twig - index.html.twig - EventBundle.php - 邮件捆绑 - 控制器 - 默认控制器.php - nieuwsbrief.php - 资源 - 配置 - 服务.yml - 意见 - 行政 - lijst.html.twig - maken.html.twig - 默认 - index.html.twig - 电子邮件 - nieuwsbrief.html.twig -registration.html.twig - MailBundle.php - 主捆绑 - 控制器 - 默认控制器.php - 资源 - 配置 - 路由.yml - 服务.yml - 意见 - 行政 -dashboard.html.twig - 默认 - index.html.twig -T - 双胞胎 - 树枝 - Extensions.php - MainBundle.php - 媒体包 - 控制器 - 默认控制器.php - 资源 - 配置 - 服务.yml - 意见 - 行政 - 专辑.html.twig - 专辑.html.twig - 创建.html.twig - 上传者.html.twig - 默认 - 专辑.html.twig - index.html.twig - MediaBundle.php - PostBundle - 控制器 - 默认控制器.php - 资源 - 配置 - 服务.yml - 意见 - 行政 - 新的.html.twig - post.html.twig -posts.html.twig - 默认 -archief.html.twig - index.html.twig - PostBundle.php - 用户捆绑 - 控制器 - 默认控制器.php - 资源 - 配置 - 服务.yml - 意见 - 行政 - bekijk.html.twig - 编辑.html.twig - 新的.html.twig - users.html.twig - 默认 - index.html.twig - UserBundle.php
问题
当我运行时,MediaBundle:DefaultController:createAction
我收到以下错误:
未找到 CoreBundle\Entity\Album 对象。
编码
MediaBundle\Controller\Defaultcontroller.php
<?php
namespace MediaBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
use ImageOptim\API;
use CoreBundle\Entity\Album;
use CoreBundle\Entity\Image;
use CoreBundle\Form\AlbumType;
use CoreBundle\Form\ImageType;
class DefaultController extends Controller {
/**
* @Route("/album/{naam}", name="home_album")
*/
public function home(Album $album){
$em = $this->getDoctrine()->getManager();
$fotos = $this->getDoctrine()->getRepository("CoreBundle:Image")->findBy(Array('albumId' => $album->getId()));
$counter = $this->getDoctrine()->getRepository('CoreBundle:Variabel')->findOneBy(Array('type' => 'counter'));
$counter->setWaarde($counter->getWaarde() + 1);
$em->persist($counter);
$em->flush();
return $this->render("MediaBundle:Default:album.html.twig", Array(
'album' => $album,
'media' => $fotos,
'counter' => $counter,
));
}
/**
* @Route("/albums", name="albums")
* @Security("has_role('ROLE_MEDEWERKER')")
*/
public function indexAction() {
$albums = $this->getDoctrine()->getRepository('CoreBundle:Album')->findAll();
return $this->render('MediaBundle:Admin:albums.html.twig', Array('page' => 'media', 'albums' => $albums));
}
/**
* @Route("/album/maken", name="albumMaken")
* @Security("has_role('ROLE_CONTENT')")
*/
public function createAction(Request $request) {
$album = new Album();
$form = $this->createForm(AlbumType::class, $album);
$form->handleRequest($request);
if ($form->isValid() && $form->isSubmitted()) {
$em = $this->getDoctrine()->getEntityManager();
$em->persist($album);
$em->flush();
$fs = new Filesystem();
if (!$fs->exists('/var/www/vhosts/saturnuslivemusic.nl/httpdocs/web/assets/images/albums/' . $album->getNaam())) {
$fs->mkdir('/var/www/vhosts/saturnuslivemusic.nl/httpdocs/web/assets/images/albums/' . $album->getNaam());
}
return $this->redirectToRoute('bekijkAlbum', Array('titel' => $album->getNaam(), 'id' => $album->getId()));
}
return $this->render('MediaBundle:Admin:create.html.twig', Array(
'page' => 'media',
'form' => $form->createView(),
));
}
/**
* @Route("/album/bewerk/{titel}/{id}", name="bewerkAlbum")
* @Security("has_role('ROLE_CONTENT')")
*/
public function bewerkAction($titel, $id) {
// Laden van de template met dropzone
$image = new Image();
$form = $this->createForm(ImageType::class, $image);
$album = $this->getDoctrine()->getRepository("CoreBundle:Album")->findOneBy(Array("id"=>$id));
return $this->render('MediaBundle:Admin:uploader.html.twig', Array(
'page'=>'media',
'album'=>$album,
'form'=>$form->createView(),
));
}
/**
* @Route("/upload/image/{id}", name="uploadImage")
*/
public function uploadAction($id, Request $request) {
// uploaden van de fotos vanuit de dropzone
$files = $request->files;
$album = $this->getDoctrine()->getRepository('CoreBundle:Album')->findOneBy(Array('id' => $id));
foreach ($files as $upfile) {
$name = str_replace(' ', '_', $upfile->getClientOriginalName());
$file = $upfile->move('/var/www/vhosts/saturnuslivemusic.nl/httpdocs/web/assets/images/albums/' . $album->getNaam() . '/', $name);
$upload = new Image();
$upload->setAlbumId($album);
$upload->setName(str_replace('_', ' ', $name));
$upload->setPath($name);
$em = $this->getDoctrine()->getManager();
$em->persist($upload);
$em->flush();
$ap = new API("hwmwskhnhb");
$img = $ap->imageFromPath('/var/www/vhosts/saturnuslivemusic.nl/httpdocs/web/assets/images/albums/' . $album->getNaam() . '/' . $upload->getPath())
->quality("low")
->getBytes();
$img = imagecreatefromstring($img);
unlink('/var/www/vhosts/saturnuslivemusic.nl/httpdocs/web/assets/images/albums/' . $album->getNaam() . '/' . $upload->getPath());
imagejpeg($img, '/var/www/vhosts/saturnuslivemusic.nl/httpdocs/web/assets/images/albums/' . $album->getNaam() . '/' . $upload->getPath());
$response = new Response();
$response->setContent(json_encode(Array(
'statusCode' => 200,
)));
$response->headers->set('Content-Type', 'application/json');
return $response;
}
}
/**
* @Route("/album/verwijder/{id}", name="verwijderAlbum")
* @Security("has_role('ROLE_CONTENT')")
*/
public function verwijderAction($id) {
}
/**
* @Route("/album/bekijk/{titel}/{id}", name="bekijkAlbum")
* @Security("has_role('ROLE_MEDEWERKER')")
*/
public function bekijkAction($titel, $id) {
$album = $this->getDoctrine()->getRepository("CoreBundle:Album")->findOneBy(Array('id' => $id));
$fotos = $this->getDoctrine()->getRepository("CoreBundle:Image")->findBy(Array('albumId' => $album->getId()));
return $this->render("MediaBundle:Admin:album.html.twig", Array(
'album' => $album,
'media' => $fotos,
'page' => 'media',
));
}
}
CoreBundle\Entity\Album.php
<?php
namespace CoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="foto_albums")
*/
class Album
{
/**
* @ORM\Column(type="string", length=255)
*/
private $naam;
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* Set naam
*
* @param string $naam
*
* @return FotoAlbums
*/
public function setNaam($naam)
{
$this->naam = $naam;
return $this;
}
/**
* Get naam
*
* @return string
*/
public function getNaam()
{
return $this->naam;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
}
我跑过的测试
检查
Album
文件是否存在。Album
文件存在于以下位置:CoreBundle\Entity\Album.php
.检查
Album
文件是否与同一控制器中的其他功能一起使用。Album
文件与同一控制器的其他功能正常工作/找到。删除缓存是否有效。
成功删除缓存,没有改变任何东西。
注释是否正确制作。
据我所知,注释是正确的。
如您所见,我已经尝试了一些,但对我没有任何帮助。