Note that there are some explanatory texts on larger screens.

plurals
  1. POmust return a string value in zend2. How?
    text
    copied!<p>I have a problem with a zend2 form. I made an entity which gets some data from the database and joins some tables...</p> <p>here is the entity:</p> <pre><code>class Campaigns { /** * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") * @ORM\Column(type="integer") */ protected $id; /** * * @ORM\Column(name="campaign_name", type="string") * */ protected $campaigns; /** * @var mixed * * @ORM\ManyToMany(targetEntity="Application\Entity\Countries", cascade={"persist"}, orphanRemoval=false) * @ORM\JoinTable(name="campaigns_countries", * joinColumns={@ORM\JoinColumn(name="campaign_id", referencedColumnName="id", onDelete="CASCADE")}, * inverseJoinColumns={@ORM\JoinColumn(name="country_id", referencedColumnName="id", onDelete="CASCADE")} * ) */ protected $countries; </code></pre> <p>Below this code are the getters and setters, a construct function, an add and an remove function.</p> <p>Here they are:</p> <pre><code>public function getId() { return $this-&gt;id; } public function setId($id) { $this-&gt;id = $id; return $this; } public function getCampaigns() { return $this-&gt;campaigns; } public function setCampaigns($campaigns) { $this-&gt;campaigns = $campaigns; return $this; } public function addCampaigns($campaigns = null) { foreach ($campaigns as $c) { if (!$this-&gt;campaigns-&gt;contains($c)) { $this-&gt;campaigns-&gt;add($c); } } } public function removeCampaigns($campaigns) { foreach ($campaigns as $c) { if ($this-&gt;campaigns-&gt;contains($c)) { $this-&gt;campaigns-&gt;removeElement($c); } } } public function getCountries() { return $this-&gt;countries; } public function setCountries($countries) { $this-&gt;countries = $countries; return $this; } public function addCountries($countries = null) { foreach ($countries as $c) { if (!$this-&gt;countries-&gt;contains($c)) { $this-&gt;countries-&gt;add($c); } } } public function removeCountries($countries) { foreach ($countries as $c) { if ($this-&gt;countries-&gt;contains($c)) { $this-&gt;countries-&gt;removeElement($c); } } } //construct for countries public function __construct() { $this-&gt;setCountries(new ArrayCollection()); } </code></pre> <p>My problem is with the <code>protected $countries</code>. If i add in the form the property value, it gives me the "countries" property not found in entity.</p> <p>If I do not add it, and instead use <code>__toString()</code> function, it gives me an error saying that it could not convert countries to string...in the <code>__toString()</code> function I added the following code:</p> <pre><code>public function __toString() { return $this-&gt;countries; } </code></pre> <p>Thank you for all your help! </p> <p>AE</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload