Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7178169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:52:01+00:00 2026-05-28T16:52:01+00:00

I have two classes: News : /** @Entity @Table(name=news) */ class News { /**

  • 0

I have two classes:

News:

/** @Entity @Table(name="news") */
class News {
    /**
     * @Id @GeneratedValue @Column(type="integer")
     * @var integer
     */
    protected $id;

    /**
     * @Column(type="string", length=100)
     * @var string
     */
    protected $title;

    /**
     * @Column(type="text")
     * @var string
     */
    protected $content;

    /**
     * @ManyToOne(targetEntity="User", inversedBy="news")
     * @JoinColumn(referencedColumnName="id")
     */ 
    protected $author;

    /**
     * @ManyToOne(targetEntity="NewsCategory", inversedBy="news")
     * @JoinColumn(referencedColumnName="id")
     */ 
    protected $category;

    /**
     * @Column(type="datetime")
     */
    protected $add_date;

    # CATEGORY methods
    public function setCategory($val) { if($val instanceof NewsCategory) $this->category = $val; }
    public function getCategory() { return $this->category; }
}

NewsCategory:

/** @Entity @Table(name="news_category") */
class NewsCategory {
    /**
     * @Id @GeneratedValue @Column(type="integer")
     * @var integer
     */
    protected $id;

    /**
     * @Column(type="string", length=50, unique=TRUE)
     * @var string
     */
    protected $name;

    /**
     * @OneToMany(targetEntity="News", mappedBy="category")
     */
    protected $news;    

    public function __construct() {
        $this->news = new \Doctrine\Common\Collections\ArrayCollection;
    }

    public function setName($name) { $this->name = $name; }
    public function getName() { return $this->name; }

    public function getNews() { return $this->news; }
}

I want to download one news with this query:

$q = $this->db->createQuery("SELECT n FROM News n WHERE n.id = :id");
$q->setParameter('id', $_GET['id']);
$news = $q->getResult();

And next, I want to get id of a Category related to this news with

$news->getCategory()->getId()

With code above, I’m getting this error:

Fatal error: Call to undefined method DoctrineProxies\NewsCategoryProxy::getId() in C:\[...]\newsController.php on line 61

What’s wrong? Why my NewsCategory class can’t see getId() method?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:52:02+00:00Added an answer on May 28, 2026 at 4:52 pm

    It’s a good practice to allways declare your class’ members private and to generate getters and setters on your class members.

    In your case, you don’t generate getters and setters (there is no getId() method on your NewCategory class).

    That’s how your NewCategory class should look like :

    /** @Entity @Table(name="news_category") */
    class NewsCategory {
        /**
         * @Id @GeneratedValue @Column(type="integer")
         * @var integer
         */
        private $id;
    
        /**
         * @Column(type="string", length=50, unique=TRUE)
         * @var string
         */
        private $name;
    
        /**
         * @OneToMany(targetEntity="News", mappedBy="category")
         */
        private $news;    
    
        public function __construct() {
            $this->news = new \Doctrine\Common\Collections\ArrayCollection;
        }
    
        public function getId(){ return $this->id;}
        public function setId($id){ $this->id = $id;}
    
        public function setName($name) { $this->name = $name; }
        public function getName() { return $this->name; }
    
        public function setNews($news) {$this->news = $news;}
        public function getNews() { return $this->news; }
    
    }
    

    The generated proxies will not generate magically getters and setters on every of your properties (it would break the OOP’s encapsulation principle).
    You can find more documentations about proxies here : http://www.doctrine-project.org/docs/orm/2.0/en/reference/configuration.html#proxy-objects

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two classes: User : /** @Entity @Table(name=users) */ class User { /**
I have two classes public class PrepaidPackage { private String name; private String serviceClassID;
I have two classes declared like this: class Object1 { protected ulong guid; protected
I have two classes: namespace Something { [Serializable] public class Spec { public string
I have two classes public class News { public virtual int Id { get;
I have two classes: class Player { public string Id { set; get; }
I have two classes, and want to include a static instance of one class
I have two classes, Foo and Bar, that have constructors like this: class Foo
I have two classes: Action and MyAction . The latter is declared as: class
I have two classes, Portfolio, and PortfolioImage. class PortfolioImage(models.Model): portfolio = models.ForeignKey('Portfolio', related_name='images') ...

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.