Reputation: 199
Hello i'm trying to select row by title
Entity\Pages.php
<?php
namespace Dproc\MainBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @IgnoreAnnotation("fn")
*
*/
/**
* @ORM\Entity
* @ORM\Table(name="pages")
*/
class Pages
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $Id;
/**
* @ORM\Column(type="text")
*/
protected $page_title;
/**
* @ORM\Column(type="text")
*/
protected $page_content;
/**
* @ORM\Column(type="text")
*/
protected $page_category;
/**
* Get Id
*
* @return integer
*/
public function getId()
{
return $this->Id;
}
/**
* Set page_title
*
* @param string $pageTitle
* @return Pages
*/
public function setPageTitle($pageTitle)
{
$this->page_title = $pageTitle;
return $this;
}
/**
* Get page_title
*
* @return string
*/
public function getPageTitle()
{
return $this->page_title;
}
/**
* Set page_content
*
* @param string $pageContent
* @return Pages
*/
public function setPageContent($pageContent)
{
$this->page_content = $pageContent;
return $this;
}
/**
* Get page_content
*
* @return string
*/
public function getPageContent()
{
return $this->page_content;
}
/**
* Set page_category
*
* @param string $pageCategory
* @return Pages
*/
public function setPageCategory($pageCategory)
{
$this->page_category = $pageCategory;
return $this;
}
/**
* Get page_category
*
* @return string
*/
public function getPageCategory()
{
return $this->page_category;
}
}
CourseController
<?php
namespace Dproc\MainBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Dproc\MainBundle\Entity\Pages;
use Symfony\Component\HttpFoundation\Response;
class CourseController extends Controller
{
public function IndexAction($slug)
{
$page = $this->getDoctrine()
->getRepository('DprocMainBundle:Pages')
->findByPageTitle($slug);
if (!$page) {
throw $this->createNotFoundException('No product found for slug '.$slug);
}
return $this->render('DprocMainBundle:Dproc:single.html.twig',array('page' => $page));
}
}
I'm trying to find it by page_title so i tried findByPageTitle($slug) but it shows
Entity 'Dproc\MainBundle\Entity\Pages' has no field 'pageTitle'. You can therefore not call 'findByPageTitle' on the entities' repository
What i'm doing wrong, and how can i select row by page_title
Upvotes: 1
Views: 2124
Reputation: 6256
Symfony's coding standards specify that you need to use camelcase syntax on your variables.
My guess is that you used the underscore syntax because you wanted your columns in your database to have underscores.
You can specify a column name by using the attribute name
to the Column
annotation.
/**
* @ORM\Column(name="page_title", type="text")
*/
protected $pageTitle;
/**
* @ORM\Column(name="page_content", type="text")
*/
protected $pageContent;
/**
* @ORM\Column(name="page_category", type="text")
*/
protected $pageCategory;
I'd highly advise you to read the coding standards so you don't get stuck in this kind of problem in the future.
Upvotes: 6
Reputation: 5599
Use this snippet in you entity :
/**
* @ORM\Column(name="page_title", type="text")
*/
protected $pageTitle;
Don't forget to modity the get and set for the field.
Try and stick to the Symfony2 standards: http://symfony.com/doc/current/contributing/code/standards.html
Upvotes: 1