TYPO3 href not working - typo3

I am quite new to TYPO3, I am inspecting a code for errors and I saw a non working href.
the inspection in the browser shows empty href :
<a class="download" target="_blank" title="Initiates file download" href=""> here..</a>
The code is :
<a class="download" target="_blank" title="Initiates file download" href="{location.pdf.originalResource.publicUrl}"><f:translate key="tx_locations_domain_model_location.here" />..</a>
I don't understand this location.pdf.originalResource.publicUrl !!
When I display {location} I get : Locations\Locations\Domain\Model\Location:102
I can't find such path in my folders !!
What am I missing !!
When I make
<f:debug>{location}</f:debug>
I see : pdf => NULL , how can I fix it, in my backend I select a PDF and saved. no error message
UPDATE:
My Pdf field is int(11) unsigned,
Here is my TCA (typo3conf/ext/locations/Configuration/TCA/Location.php)
$GLOBALS['TCA']['tx_locations_domain_model_location'] = array(
....
'columns' => array(
....
'pdf' => array(
'exclude' => 1,
'label' => 'LLL:EXT:locations/Resources/Private/Language/locallang_db.xlf:tx_locations_domain_model_location.pdf',
'config' => array (
'type' => 'group',
'internal_type' => 'file',
'allowed' => $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'],
'max_size' => $GLOBALS['TYPO3_CONF_VARS']['BE']['maxFileSize'],
'uploadfolder' => 'uploads/pics',
'show_thumbs' => 1,
'size' => 1,
'minitems' => 0,
'maxitems' => 1
)
),
here is my Location class :
<?php
namespace Locations\Locations\Domain\Model;
/**
* Location
*/
class Location extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
/**
* title
*
* #var string
*/
protected $title = '';
/**
* fullTitle
*
* #var string
*/
protected $fullTitle = '';
/**
* description
*
* #var string
*/
protected $description = '';
/**
* image
*
* #var \TYPO3\CMS\Extbase\Domain\Model\FileReference
*/
protected $image = NULL;
/**
* secondTitle
*
* #var string
*/
protected $secondTitle = '';
/**
* secondDescription
*
* #var string
*/
protected $secondDescription = '';
/**
* address
*
* #var string
*/
protected $address = '';
/**
* howToGetIt
*
* #var string
*/
protected $howToGetIt = '';
/**
* thirdTitle
*
* #var string
*/
protected $thirdTitle = '';
/**
* thirdDescription
*
* #var string
*/
protected $thirdDescription = '';
/**
* googleMap
*
* #var string
*/
protected $googleMap = '';
/**
* pdf
*
* #var \TYPO3\CMS\Extbase\Domain\Model\FileReference
*/
protected $pdf = NULL;
/**
* pricingtpl
*
* #var int
*/
protected $pricingtpl;
/**
* category
*
* #var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Locations\Locations\Domain\Model\Category>
*/
protected $category = NULL;
/**
* __construct
*/
public function __construct() {
//Do not remove the next line: It would break the functionality
$this->initStorageObjects();
}
/**
* Initializes all ObjectStorage properties
* Do not modify this method!
* It will be rewritten on each save in the extension builder
* You may modify the constructor of this class instead
*
* #return void
*/
protected function initStorageObjects() {
$this->category = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
}
/**
* Returns the title
*
* #return string $title
*/
public function getTitle() {
return $this->title;
}
/**
* Sets the image
*
* #param \TYPO3\CMS\Extbase\Domain\Model\FileReference $image
* #return void
*/
public function setImage(\TYPO3\CMS\Extbase\Domain\Model\FileReference $image) {
$this->image = $image;
}
/**
* Sets the pdf
*
* #param \TYPO3\CMS\Extbase\Domain\Model\FileReference $pdf
* #return void
*/
public function setPdf(\TYPO3\CMS\Extbase\Domain\Model\FileReference $pdf) {
$this->pdf = $pdf;
}
/**
* Removes a Category
*
* #param \Locations\Locations\Domain\Model\Category $categoryToRemove The Category to be removed
* #return void
*/
public function removeCategory(\Locations\Locations\Domain\Model\Category $categoryToRemove) {
$this->category->detach($categoryToRemove);
}
/**
* Returns the category
*
* #return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Locations\Locations\Domain\Model\Category> $category
*/
public function getCategory() {
return $this->category;
}
/**
* Sets the category
*
* #param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Locations\Locations\Domain\Model\Category> $category
* #return void
*/
public function setCategory(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $category) {
$this->category = $category;
}
}

Your model Location.php file. You can't define getPdf() method only use set method. Please define first getPdf() method in your Location.php file.
Like this.
/**
* Returns the pdf
*
* #return \TYPO3\CMS\Extbase\Domain\Model\FileReference $pdf
*/
public function getPdf() {
return $this->Pdf;
}
After you can debug your .html file like this <f:debug>{_all}</f:debug> and see the debug output.

You don't have to use in Fluid things like <a href=""/>, you can find the <f:link..>, <f:uri..>,etc, in fluid documentation for generating links.
But there for file downloading you have to use this viewhelper. You have to know only the uid of the file. In your case {location.pdf.uid} Be sure that you have indexed files before use it.
<v:resource.file additionalAttributes="{foo: 'bar'}" data="{foo: 'bar'}" identifier="[mixed]" categories="[mixed]" treatIdAsUid="1" treatIdAsReference="1" as="NULL">
<!-- tag content - may be ignored! -->
</v:resource.file>

Related

TYPO3 filereference adding two files

I have TYPO3 7.6.18
this is my code:
$newVideo = new \Istar\Fefiles\Domain\Model\Video();
$videoName = $video['name'];
$videoTmpName = $video['tmp_name'];
$resourceFactory = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance();
$storage = $resourceFactory->getDefaultStorage();
$folder = $storage->getFolder("user_upload/");
$movedFile = $storage->addFile($videoTmpName, $folder, $videoName);
$newFileReference = $this->objectManager$this->objectManager->get('TYPO3\\CMS\\Extbase\\Domain\\Model\\FileReference');
$newFileReference->setFile($movedFile);
$newVideo->setVideo($newFileReference);
$this->videoRepository->add($newVideo);
$persistenceManager = $this->objectManager->get("TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager");
$persistenceManager->persistAll();
The problem is it added two files to field video file reference. It's very sudenly! And second file is't the same, it's diferent files. I sure, I send one file. Where may be the problem ?
I have model photo, and there is field image
'image' => [
'exclude' => 0,
'label' => 'LLL:EXT:fefiles/Resources/Private/Language/locallang_db.xlf:image',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig('image', [
'appearance' => [
'createNewRelationLinkTitle' => 'LLL:EXT:cms/locallang_ttc.xlf:images.addFileReference'
],
'maxitems' => 1,
], $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'])
],
Anf I see that when I create photo from BE, and upload image - this add second image, which was uploaded on site early. This is very strange! What happens ?
My video model:
<?php
namespace Istar\Fefiles\Domain\Model;
class Video extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
{
/**
* #var bool
*/
public $allow_for_user = true;
/**
* Title
*
* #var string
* #validate NotEmpty
*/
protected $title = '';
/**
* Description
*
* #var string
*/
protected $description = '';
/**
* rulesDescription
*
* #var string
*/
protected $rulesDescription = '';
/**
* User
*
* #var \Fhk\Feusersplus\Domain\Model\User>
*/
protected $user;
/**
* Videocategory
*
* #var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Istar\Fefiles\Domain\Model\Videocategory>
*/
protected $videocategory;
/**
* Videocomment
*
* #var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Istar\Fefiles\Domain\Model\Videocomment>
* #cascade remove
*/
protected $comment;
/**
* Allow
*
* #var int
*/
protected $allow = 0;
/**
* fskcheck
*
* #var int
*/
protected $fskcheck = 0;
/**
* private
*
* #var int
*/
protected $private = 0;
/**
* Video
* #validate NotEmpty
* #var \TYPO3\CMS\Extbase\Domain\Model\FileReference
* #cascade remove
*/
protected $video;
/**
* preview
*
* #var \TYPO3\CMS\Extbase\Domain\Model\FileReference
* #cascade remove
*/
protected $preview = null;
/**
* blurred
*
* #var \TYPO3\CMS\Extbase\Domain\Model\FileReference
* #cascade remove
*/
protected $blurred = null;
/**
* Crdate
*
* #var int
* #validate NotEmpty
*/
protected $crdate = 0;
/**
* Returns the title
*
* #return string $title
*/
public function getTitle()
{
return $this->title;
}
/**
* Sets the title
*
* #param string $title
* #return void
*/
public function setTitle($title)
{
$this->title = $title;
}
/**
* Returns the description
*
* #return string $description
*/
public function getDescription()
{
return $this->description;
}
/**
* Sets the description
*
* #param string $description
* #return void
*/
public function setDescription($description)
{
$this->description = $description;
}
/**
* Returns the rulesDescription
*
* #return string $rulesDescription
*/
public function getRulesDescription()
{
return $this->rulesDescription;
}
/**
* Sets the rulesDescription
*
* #param string $rulesDescription
* #return void
*/
public function setRulesDescription($rulesDescription)
{
$this->rulesDescription = $rulesDescription;
}
/**
* Returns the video
*
* #return \TYPO3\CMS\Extbase\Domain\Model\FileReference $video
*/
public function getVideo()
{
return $this->video;
}
/**
* Returns the videocategory
*
* #return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Istar\Fefiles\Domain\Model\Videocategory> $videocategory
*/
public function getVideocategory()
{
return $this->videocategory;
}
/**
* Sets the videocategory
*
* #return void
*/
public function setVideocategory($videocategory)
{
$this->videocategory = $videocategory;
}
/**
* Returns the comment
*
* #return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Istar\Fefiles\Domain\Model\Videocomment> $comment
*/
public function getComment()
{
return $this->comment;
}
/**
* Sets the comment
*
* #return void
*/
public function setComment($comment)
{
$this->comment = $comment;
}
/**
* Adds a comments to the video
*
* #param \Istar\Fefiles\Domain\Model\Videocomment $comment
* #return void
* #api
*/
public function addComment(\Istar\Fefiles\Domain\Model\Videocomment $comment)
{
$this->comment->attach($comment);
}
/**
* Removes a comment from the video
*
* #param \Istar\Fefiles\Domain\Model\Videocomment $comment
* #return void
* #api
*/
public function removeComment(\Istar\Fefiles\Domain\Model\Videocomment $comment)
{
$this->comment->detach($comment);
}
/**
* Returns the user
*
* #return \Fhk\Feusersplus\Domain\Model\User> $user
*/
public function getUser()
{
return $this->user;
}
/**
* Sets the user
*
* #return void
*/
public function setUser($user)
{
$this->user = $user;
}
/**
* Returns the allow
*
* #return int
*/
public function getAllow()
{
return $this->allow;
}
/**
* Sets the video
*
* #param \TYPO3\CMS\Extbase\Domain\Model\FileReference $video
* #return void
*/
public function setVideo($video)
{
$this->video = $video;
}
/**
* Returns the preview
*
* #return \TYPO3\CMS\Extbase\Domain\Model\FileReference $preview
*/
public function getPreview()
{
return $this->preview;
}
/**
* Sets the preview
*
* #param \TYPO3\CMS\Extbase\Domain\Model\FileReference $preview
*
* #return void
*/
public function setPreview($preview)
{
$this->preview = $preview;
}
/**
* Returns the blurred
*
* #return \TYPO3\CMS\Extbase\Domain\Model\FileReference $blurred
*/
public function getBlurred()
{
return $this->blurred;
}
/**
* Sets the blurred
*
* #param \TYPO3\CMS\Extbase\Domain\Model\FileReference $blurred
*
* #return void
*/
public function setBlurred($blurred)
{
$this->blurred = $blurred;
}
/**
* Returns the fskcheck
*
* #return int
*/
public function getFskcheck()
{
return $this->fskcheck;
}
/**
* Sets the fskcheck
*
* #return void
*/
public function setFskcheck($fskcheck)
{
$this->fskcheck = $fskcheck;
}
/**
* Returns the Private
*
* #return int
*/
public function getPrivate()
{
return $this->private;
}
/**
* Sets the private
*
* #return void
*/
public function setPrivate($private)
{
$this->private = $private;
}
/**
* Returns the crdate
* #return int $crdate
*/
public function getCrdate()
{
return $this->crdate;
}
/**
* Sets the crdate
*
* #param int $crdate
* #return void
*/
public function setCrdate($crdate)
{
$this->crdate = $crdate;
}
}
Have a look at the sys_file_reference table before and after you create a new record in the backend. Is there a new record added? And after saving an existing record you don't get the random image/video added?
Solution:
'foreign_match_fields' => array(
'fieldname' => 'image',
'tablenames' => 'tx_fefiles_domain_model_photo',
'table_local' => 'sys_file_reference',
),

How to choose displayed field of a form after 'choices' findall?

I would like to choose an other field to display in my form checkboxes.
My Entity Filter has three attributes id, name and subtitle.
My code displays my name values, how to display subtitle values ?
My FormBuilder (Controller):
$formFilter = $this->createFormBuilder()
->add('_', ChoiceType::class,array(
'choices' => $this->getDoctrine()->getManager()->getRepository('loicFilterBundle:Filter')->findAll(),
'multiple' => true,
'expanded' => true,
'choice_label' => function($value, $key, $index) {
return ($value);
},
))
->add('Appliquer filtres', SubmitType::class)
->getForm();
Filter:
namespace loic\FilterBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Filter
*
* * #ORM\Entity(repositoryClass="loic\FilterBundle\Entity\FilterRepository")
* #ORM\Table(name="filter", uniqueConstraints={#ORM\UniqueConstraint(name="idfilter_UNIQUE", columns={"idfilter"})}, indexes={#ORM\Index(name="fk_filter_filter_category1_idx", columns={"filter_category_idfilter_category"})})
*/
class Filter
{
/**
* #var integer
*
* #ORM\Column(name="idfilter", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $idfilter;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=45, nullable=true)
*/
private $name;
/**
* #var \FilterCategory
*
* #ORM\ManyToOne(targetEntity="FilterCategory")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="filter_category_idfilter_category", referencedColumnName="idfilter_category")
* })
*/
private $filterCategoryfilterCategory;
/**
* #var \Doctrine\Common\Collections\Collection
*
* #ORM\ManyToMany(targetEntity="loic\ContentBundle\Entity\Content", mappedBy="filterfilter")
*/
private $contentcontent;
/**
* #var \Doctrine\Common\Collections\Collection
*
* #ORM\ManyToMany(targetEntity="loic\UserBundle\Entity\User", mappedBy="filterfilter")
*/
private $user;
/**
* #var string
*
* #ORM\Column(name="subtitle", type="string", length=45, nullable=true)
*/
private $subtitle;
/**
* #var string
*
* #ORM\Column(name="description", type="string", length=45, nullable=true)
*/
private $description;
/**
* #var string
*
* #ORM\Column(name="status", type="string", length=45, nullable=false)
*/
private $status;
/**
* Constructor
*/
public function __construct()
{
$this->contentcontent = new \Doctrine\Common\Collections\ArrayCollection();
$this->user = new \Doctrine\Common\Collections\ArrayCollection();
$this->status = 1;
}
/**
*
* #return the integer
*/
public function getIdfilter() {
return $this->idfilter;
}
/**
*
* #param
* $idfilter
*/
public function setIdfilter($idfilter) {
$this->idfilter = $idfilter;
return $this;
}
/**
*
* #return the string
*/
public function getName() {
return $this->name;
}
/**
*
* #param
* $name
*/
public function setName($name) {
$this->name = $name;
return $this;
}
/**
*
* #return the \FilterCategory
*/
public function getFilterCategoryfilterCategory() {
return $this->filterCategoryfilterCategory;
}
/**
*
* #param \FilterCategory $filterCategoryfilterCategory
*/
public function setFilterCategoryfilterCategory($filterCategoryfilterCategory) {
$this->filterCategoryfilterCategory = $filterCategoryfilterCategory;
return $this;
}
/**
*
* #return the \Doctrine\Common\Collections\Collection
*/
public function getContentcontent() {
return $this->contentcontent;
}
/**
*
* #param
* $contentcontent
*/
public function setContentcontent($contentcontent) {
$this->contentcontent = $contentcontent;
return $this;
}
public function __toString(){
return $this->name;
}
/**
*
* #return the \Doctrine\Common\Collections\Collection
*/
public function getUser() {
return $this->user;
}
/**
*
* #param
* $user
*/
public function setUser($user) {
$this->user = $user;
return $this;
}
/**
*
* #return the string
*/
public function getSubtitle() {
return $this->subtitle;
}
/**
*
* #param
* $subtitle
*/
public function setSubtitle($subtitle) {
$this->subtitle = $subtitle;
return $this;
}
/**
*
* #return the string
*/
public function getDescription() {
return $this->description;
}
/**
*
* #param
* $description
*/
public function setDescription($description) {
$this->description = $description;
return $this;
}
/**
*
* #return the string
*/
public function getStatus() {
return $this->status;
}
/**
*
* #param
* $status
*/
public function setStatus($status) {
$this->status = $status;
return $this;
}
}
You should switch your from field type to EntityType (extends ChoiceType).
There you can overwrite the way the choice_label property is generated.
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
$builder->add('category', EntityType::class, array(
'class' => 'AppBundle:Category',
'choice_label' => function ($category) {
return $category->getDisplayName();
}
));
Sorce: http://symfony.com/doc/current/reference/forms/types/entity.html
Thank you it works. ;)
Also, we can just write the field name like:
'choice_label' => 'subtitle', .
However I wonder how the field was choosen with my previous code.

How to use Catalog rule "Conditions_serialized" to validate product attribute?

I have define a condition the which product as product attribute "Hot" equal to "yes" on my table "product_label".
How to use \Magento\CatalogRule\Model\Rule\Condition... to validate $product with my condition?
The condition is record as following
a:7:{s:4:"type";s:48:"Magento\CatalogRule\Model\Rule\Condition
\Combine";s:9:"attribute";N;s:8:"operator";N;s:5:"value";s:1:"1";s:18:"is_value_
processed";N;s:10:"aggregator";s:3:"all";s:10:"conditions";a:1:{i:0;a:5:
{s:4:"type";s:48:"Magento\CatalogRule\Model\Rule\Condition
\Product";s:9:"attribute";s:7:"hkt_hot";s:8:"operator";s:2:"==";s:5:"value";
s:1:"1";s:18:"is_value_processed";b:0;}}}
Thanks
Norman
Without coding you can make this check using the system already in place:
Your "hot" attribute property is_used_for_promo_rules must be set to 1.
Additionally, the function Mage_Catalog_Model_Resource_Eav_Attribute::isAllowedForRuleCondition() sets the following prerequisites:
An attribute must be visible (attribute property is_visible must be equal 1).
The frontend_input property must be one of the following types: ‘text’, ‘multiselect’, ‘textarea’, ‘date’, ‘datetime’, ‘select’, ‘boolean’, ‘price’.
You may find the list of product IDs satisfying the serialized conditions.
Create model Vendor/Module/Model/Rule.php
<?php
namespace Vendor\Module\Model;
class Rule extends \Magento\CatalogRule\Model\Rule
{
/**
* Prefix of model events names
*
* #var string
*/
protected $_eventPrefix = 'catalogrule_rule';
/**
* Parameter name in event
*
* In observe method you can use $observer->getEvent()->getRule() in this case
*
* #var string
*/
protected $_eventObject = 'rule';
/**
* Store matched product Ids
*
* #var array
*/
protected $_productIds;
/**
* Limitation for products collection
*
* #var int|array|null
*/
protected $_productsFilter = null;
/**
* Store current date at "Y-m-d H:i:s" format
*
* #var string
*/
protected $_now;
/**
* Cached data of prices calculated by price rules
*
* #var array
*/
protected static $_priceRulesData = [];
/**
* Catalog rule data
*
* #var \Magento\CatalogRule\Helper\Data
*/
protected $_catalogRuleData;
/**
*
* #var \Magento\Framework\App\Cache\TypeListInterface
*/
protected $_cacheTypesList;
/**
*
* #var array
*/
protected $_relatedCacheTypes;
/**
*
* #var \Magento\Framework\Stdlib\DateTime
*/
protected $dateTime;
/**
*
* #var \Magento\Framework\Model\ResourceModel\Iterator
*/
protected $_resourceIterator;
/**
*
* #var \Magento\Customer\Model\Session
*/
protected $_customerSession;
/**
*
* #var \Magento\CatalogRule\Model\Rule\Condition\CombineFactory
*/
protected $_combineFactory;
/**
*
* #var \Magento\CatalogRule\Model\Rule\Action\CollectionFactory
*/
protected $_actionCollectionFactory;
/**
*
* #var \Magento\Catalog\Model\ProductFactory
*/
protected $_productFactory;
/**
*
* #var \Magento\Store\Model\StoreManagerInterface
*/
protected $_storeManager;
/**
*
* #var \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory
*/
protected $_productCollectionFactory;
/**
*
* #var \Magento\CatalogRule\Model\Indexer\Rule\RuleProductProcessor;
*/
protected $_ruleProductProcessor;
/**
*
* #var Data\Condition\Converter
*/
protected $ruleConditionConverter;
/**
* Rule constructor.
*
* #param \Magento\Framework\Model\Context $context
* #param \Magento\Framework\Registry $registry
* #param \Magento\Framework\Data\FormFactory $formFactory
* #param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
* #param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory
* #param \Magento\Store\Model\StoreManagerInterface $storeManager
* #param Rule\Condition\CombineFactory $combineFactory
* #param Rule\Action\CollectionFactory $actionCollectionFactory
* #param \Magento\Catalog\Model\ProductFactory $productFactory
* #param \Magento\Framework\Model\ResourceModel\Iterator $resourceIterator
* #param \Magento\Customer\Model\Session $customerSession
* #param \Magento\CatalogRule\Helper\Data $catalogRuleData
* #param \Magento\Framework\App\Cache\TypeListInterface $cacheTypesList
* #param \Magento\Framework\Stdlib\DateTime $dateTime
* #param Indexer\Rule\RuleProductProcessor $ruleProductProcessor
* #param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
* #param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
* #param array $relatedCacheTypes
* #param array $data
*
* #SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Data\FormFactory $formFactory, \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\CatalogRule\Model\Rule\Condition\CombineFactory $combineFactory, \Magento\CatalogRule\Model\Rule\Action\CollectionFactory $actionCollectionFactory, \Magento\Catalog\Model\ProductFactory $productFactory, \Magento\Framework\Model\ResourceModel\Iterator $resourceIterator, \Magento\Customer\Model\Session $customerSession, \Magento\CatalogRule\Helper\Data $catalogRuleData, \Magento\Framework\App\Cache\TypeListInterface $cacheTypesList, \Magento\Framework\Stdlib\DateTime $dateTime, \Magento\CatalogRule\Model\Indexer\Rule\RuleProductProcessor $ruleProductProcessor, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $relatedCacheTypes = [], array $data = [])
{
parent::__construct($context, $registry, $formFactory, $localeDate, $productCollectionFactory, $storeManager, $combineFactory, $actionCollectionFactory, $productFactory, $resourceIterator, $customerSession, $catalogRuleData, $cacheTypesList, $dateTime, $ruleProductProcessor, $resource, $resourceCollection, $relatedCacheTypes, $data);
}
/**
* Init resource model and id field
*
* #return void
*/
protected function _construct()
{
parent::_construct();
$this->_init('Magento\CatalogRule\Model\ResourceModel\Rule');
$this->setIdFieldName('rule_id');
}
/**
* Getter for rule conditions collection
*
* #return \Magento\Rule\Model\Condition\Combine
*/
public function getConditionsInstance()
{
return $this->_combineFactory->create();
}
/**
* Getter for rule actions collection
*
* #return \Magento\CatalogRule\Model\Rule\Action\Collection
*/
public function getActionsInstance()
{
return $this->_actionCollectionFactory->create();
}
public function toArray(array $arrAttributes = array())
{
return parent::toArray($arrAttributes);
}
public function getListProductIds()
{
$productCollection = \Magento\Framework\App\ObjectManager::getInstance()->create('\Magento\Catalog\Model\ResourceModel\Product\Collection');
$productFactory = \Magento\Framework\App\ObjectManager::getInstance()->create('\Magento\Catalog\Model\ProductFactory');
$this->_productIds = [];
$this->setCollectedAttributes([]);
$this->getConditions()->collectValidatedAttributes($productCollection);
\Magento\Framework\App\ObjectManager::getInstance()->create('\Magento\Framework\Model\ResourceModel\Iterator')->walk($productCollection->getSelect(), [
[
$this,
'callbackValidateProduct'
]
], [
'attributes' => $this->getCollectedAttributes(),
'product' => $productFactory->create()
]);
return $this->_productIds;
}
/**
* Callback function for product matching
*
* #param array $args
* #return void
*/
public function callbackValidateProduct($args)
{
$product = clone $args['product'];
$product->setData($args['row']);
$websites = $this->_getWebsitesMap();
foreach ($websites as $websiteId => $defaultStoreId) {
$product->setStoreId($defaultStoreId);
if ($this->getConditions()->validate($product)) {
$this->_productIds[] = $product->getId();
}
}
}
/**
* Prepare website map
*
* #return array
*/
protected function _getWebsitesMap()
{
$map = [];
$websites = \Magento\Framework\App\ObjectManager::getInstance()->create('\Magento\Store\Model\StoreManagerInterface')->getWebsites();
foreach ($websites as $website) {
// Continue if website has no store to be able to create catalog rule for website without store
if ($website->getDefaultStore() === null) {
continue;
}
$map[$website->getId()] = $website->getDefaultStore()->getId();
}
return $map;
}
}
Then, wherever you'd like to find the product IDs. Use below code snippet.
...
private $ruleModel;
...
...
private function getRuleModel()
{
if($this->ruleModel === null) {
$this->ruleModel = $this->objectManager->create('Vendor\Module\Model\Rule');
$this->ruleModel->setName('name')
->setDescription('description')
->setWebsiteIds($this->objectManager->get('Magento\Store\Model\StoreManagerInterface')->getStore()->getWebsiteId());
}
return $this->ruleModel;
}
...
...
// somewhere in your method
$matchedProductIds = $this->getRuleModel()
->setData('conditions_serialized', $conditions_serialized)->getListProductIds();
...

I get error when I created one form with 2 entities mapped

I have 2 entities, Topic.php and Post.php I would like to have this:
TopicType.php :
<?php
namespace BISSAP\ForumBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class TopicType extends AbstractType
{
/**
* #param FormBuilderInterface $builder
* #param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('title', 'text', array(
'label' => 'Titre'))
->add('subForm', new PostType())
->add('save', 'submit', array(
'attr' => array(
'class' => 'btn right-flt')))
;
}
/**
* #param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'BISSAP\ForumBundle\Entity\Topic'
));
}
/**
* #return string
*/
public function getName()
{
return 'bissap_forumbundle_topic';
}
}
PostType.php :
<?php
namespace BISSAP\ForumBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class PostType extends AbstractType
{
/**
* #param FormBuilderInterface $builder
* #param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('content', 'ckeditor', array(
'label' => 'Votre message',
'config_name' => 'my_custom_config',
'config' => array('language' => 'fr')))
;
}
/**
* #param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'BISSAP\ForumBundle\Entity\Post'
));
}
/**
* #return string
*/
public function getName()
{
return 'bissap_forumbundle_post';
}
}
Topic.php :
<?php
namespace BISSAP\ForumBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/*use BISSAP\BodyConcept\Entity\Forum;
*/
/**
* Topic
*
* #ORM\Table()
* #ORM\Entity(repositoryClass="BISSAP\ForumBundle\Entity\TopicRepository")
*/
class Topic
{
/**
* #ORM\ManyToOne(targetEntity="Forum", inversedBy="Topics", cascade={"persist"})
* #ORM\JoinColumn(nullable=false)
*/
private $forum;
/**
* #var ArrayCollection $Posts
*
* #ORM\OneToMany(targetEntity="Post", mappedBy="Topic", cascade={"persist", "remove", "merge"})
*/
private $posts;
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="title", type="string", length=255)
*/
private $title;
/**
* #ORM\ManyToOne(targetEntity="BISSAP\UserBundle\Entity\User", inversedBy="Topics", cascade={"persist"})
* #ORM\JoinColumn(nullable=false)
*/
private $user;
/**
* #var integer
*
* #ORM\Column(name="view_count", type="integer")
*/
private $viewCount;
/**
* #var \DateTime
*
* #ORM\Column(name="date_creation", type="datetime")
*/
private $dateCreation;
/**
* #var integer
*
* #ORM\Column(name="reply_count", type="integer")
*/
private $replyCount;
/**
* #var string
*
* #ORM\Column(name="slug", type="string", length=255)
*/
private $slug;
/**
* #var string
*
* #ORM\Column(name="genre", type="string", length=255)
*/
private $genre;
/**
* #var integer
*
* #ORM\Column(name="last_post", type="integer")
*/
private $lastPost;
/**
* #var string
*
* #ORM\Column(name="content", type="text")
*/
private $content;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set title
*
* #param string $title
* #return Topic
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* #return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set user
*
* #param integer $user
* #return Topic
*/
public function setUser($user)
{
$this->user = $user;
return $this;
}
/**
* Get user
*
* #return integer
*/
public function getUser()
{
return $this->user;
}
/**
* Set viewCount
*
* #param integer $viewCount
* #return Topic
*/
public function setViewCount($viewCount)
{
$this->viewCount = $viewCount;
return $this;
}
/**
* Get viewCount
*
* #return integer
*/
public function getViewCount()
{
return $this->viewCount;
}
/**
* Set dateCreation
*
* #param \DateTime $dateCreation
* #return Topic
*/
public function setDateCreation($dateCreation)
{
$this->dateCreation = $dateCreation;
return $this;
}
/**
* Get dateCreation
*
* #return \DateTime
*/
public function getDateCreation()
{
return $this->dateCreation;
}
/**
* Set replyCount
*
* #param integer $replyCount
* #return Topic
*/
public function setReplyCount($replyCount)
{
$this->replyCount = $replyCount;
return $this;
}
/**
* Get replyCount
*
* #return integer
*/
public function getReplyCount()
{
return $this->replyCount;
}
/**
* Set slug
*
* #param string $slug
* #return Topic
*/
public function setSlug($slug)
{
$this->slug = $slug;
return $this;
}
/**
* Get slug
*
* #return string
*/
public function getSlug()
{
return $this->slug;
}
/**
* Set genre
*
* #param string $genre
* #return Topic
*/
public function setGenre($genre)
{
$this->genre = $genre;
return $this;
}
/**
* Get genre
*
* #return string
*/
public function getGenre()
{
return $this->genre;
}
/**
* Set lastPost
*
* #param integer $lastPost
* #return Topic
*/
public function setLastPost($lastPost)
{
$this->lastPost = $lastPost;
return $this;
}
/**
* Get lastPost
*
* #return integer
*/
public function getLastPost()
{
return $this->lastPost;
}
/**
* Set content
*
* #param string $content
* #return Topic
*/
public function setContent($content)
{
$this->content = $content;
return $this;
}
/**
* Get content
*
* #return string
*/
public function getContent()
{
return $this->content;
}
/**
* Set forum
*
* #param Forum $forum
* #return Topic
*/
/*public function setForum(\BISSAP\BodyConceptBundle\Entity\Forum $forum)*/
public function setForum(Forum $forum)
{
$this->forum = $forum;
return $this;
}
/**
* Get forum
*
* #return \BISSAP\BodyConceptBundle\Entity\Forum
*/
public function getForum()
{
return $this->forum;
}
/**
* Constructor
*/
public function __construct()
{
$this->posts = new \Doctrine\Common\Collections\ArrayCollection();
$this->dateCreation = new \DateTime();
}
/**
* Add posts
*
* #param \BISSAP\ForumBundle\Entity\Post $posts
* #return Topic
*/
public function addPost(\BISSAP\ForumBundle\Entity\Post $posts)
{
$this->posts[] = $posts;
return $this;
}
/**
* Remove posts
*
* #param \BISSAP\ForumBundle\Entity\Post $posts
*/
public function removePost(\BISSAP\ForumBundle\Entity\Post $posts)
{
$this->posts->removeElement($posts);
}
/**
* Get posts
*
* #return \Doctrine\Common\Collections\Collection
*/
public function getPosts()
{
return $this->posts;
}
}
Post.php :
<?php
namespace BISSAP\ForumBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Post
*
* #ORM\Table()
* #ORM\Entity(repositoryClass="BISSAP\ForumBundle\Entity\PostRepository")
*/
class Post
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\ManyToOne(targetEntity="BISSAP\UserBundle\Entity\User", inversedBy="Posts", cascade={"persist"})
* #ORM\JoinColumn(nullable=false)
*/
private $user;
/**
* #var string
*
* #ORM\Column(name="content", type="text")
*/
private $content;
/**
* #var \DateTime
*
* #ORM\Column(name="date_creation", type="datetime")
*/
private $dateCreation;
/**
* #var \DateTime
*
* #ORM\Column(name="date_modif", type="datetime")
*/
private $dateModif;
/**
* #var string
*
* #ORM\Column(name="slug", type="string", length=255)
*/
private $slug;
/**
* #ORM\ManyToOne(targetEntity="Topic", inversedBy="Posts", cascade={"persist"})
* #ORM\JoinColumn(nullable=false)
*/
private $topic;
/**
* Constructor
*/
public function __construct()
{
$this->dateCreation = new \DateTime();
$this->dateModif = new \DateTime();
}
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set content
*
* #param string $content
* #return Post
*/
public function setContent($content)
{
$this->content = $content;
return $this;
}
/**
* Get content
*
* #return string
*/
public function getContent()
{
return $this->content;
}
/**
* Set dateCreation
*
* #param \DateTime $dateCreation
* #return Post
*/
public function setDateCreation($dateCreation)
{
$this->dateCreation = $dateCreation;
return $this;
}
/**
* Get dateCreation
*
* #return \DateTime
*/
public function getDateCreation()
{
return $this->dateCreation;
}
/**
* Set dateModif
*
* #param \DateTime $dateModif
* #return Post
*/
public function setDateModif($dateModif)
{
$this->dateModif = $dateModif;
return $this;
}
/**
* Get dateModif
*
* #return \DateTime
*/
public function getDateModif()
{
return $this->dateModif;
}
/**
* Set slug
*
* #param string $slug
* #return Post
*/
public function setSlug($slug)
{
$this->slug = $slug;
return $this;
}
/**
* Get slug
*
* #return string
*/
public function getSlug()
{
return $this->slug;
}
/**
* Set Topic
*
* #param Topic $topic
* #return Post
*/
/*public function setTopic(\BISSAP\ForumBundle\Entity\Topic $topic)*/
public function setTopic(Topic $topic)
{
$this->topic = $topic;
return $this;
}
/**
* Get Topic
*
* #return \BISSAP\ForumBundle\Entity\Topic
*/
public function getTopic()
{
return $this->topic;
}
/**
* Set user
*
* #param \BISSAP\ForumBundle\Entity\User $user
* #return Post
*/
public function setUser(\BISSAP\UserBundle\Entity\User $user)
{
$this->user = $user;
return $this;
}
/**
* Get user
*
* #return \BISSAP\UserBundle\Entity\User
*/
public function getUser()
{
return $this->user;
}
}
And this is my part of my controller, here i call and use the form:
public function categoryAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$topic = new \BISSAP\ForumBundle\Entity\Topic();
$form = $this->createForm(new TopicType(), $topic);
$user = $this->getUser();
$forum = $em->getRepository('BISSAPForumBundle:Forum')->find(1);
if ($form->handleRequest($request)->isValid()) {
$topic->setUser($user);
$topic->setForum($forum);
$topic->setViewCount(23);
$topic->setReplyCount(123);
$topic->setLastPost(25);
$topic->setSlug('slug_sluggg');
$topic->setGenre('genre');
$em->persist($topic);
$em->flush();
return $this->render('BISSAPForumBundle:F:topic-forum.html.twig', array('user' => $user, 'topic' => $topic));
}
return $this->render('BISSAPForumBundle:F:category-forum.html.twig', array('listTopics' => $listTopics, 'catId' => $catId, 'form' => $form->createView(), 'user' => $user));
}
I have this error : Neither the property "subForm" nor one of the methods "getSubForm()", "isSubForm()", "hasSubForm()", "__get()" exist and have public access in class "BISSAP\ForumBundle\Entity\Topic".
Sur the way is wrong, cause i think, I need to give "$topic objexct" and "$post object" when i used :
$form = $this->createForm(new TopicType(), $topic);
And I had tried, with add(collection) i get similar error!
Thanks U.
The error you get is because you don't have "subform" attribute in your topic class. That name should correspond to the name of the attribute in your topic class.
So this:
->add('subForm', new PostType())
Should be changed to
$builder->add('posts','collection', array( 'type' => new PostType()))
This would be helpful.

Working with Doctrine 2 in Zend Framework 2 Form and fieldset using DoctrineHydrator

Client Entity
<?php
namespace Application\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Client
*
* #ORM\Table(name="client", uniqueConstraints={#ORM\UniqueConstraint(name="mail", columns=
* {"mail"}), #ORM\UniqueConstraint(name="pseudo", columns={"pseudo"})}, indexes=
* {#ORM\Index(name="FK_client_situation", columns={"situation"}),
*#ORM\Index(name="FK_client_city", columns={"ville"})})
* #ORM\Entity
*/
class Client
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var string
*
* #ORM\Column(name="firstname", type="string", length=255, nullable=true)
*/
private $firstname;
/**
* #var string
*
* #ORM\Column(name="lastname", type="string", length=255, nullable=true)
*/
private $lastname;
/**
* #var \DateTime
*
* #ORM\Column(name="birthay", type="datetime", nullable=true)
*/
private $birthay;
/**
* #var string
*
* #ORM\Column(name="mail", type="string", length=255, nullable=true)
*/
private $mail;
/**
* #var string
*
* #ORM\Column(name="phone", type="text", nullable=true)
*/
private $phone;
/**
* #var string
*
* #ORM\Column(name="pseudo", type="string", length=255, nullable=true)
*/
private $pseudo;
/**
* #var string
*
* #ORM\Column(name="password", type="string", length=255, nullable=true)
*/
private $password;
/**
* #var integer
*
* #ORM\Column(name="situation", type="integer", nullable=true)
*/
private $situation;
/**
* #var integer
*
* #ORM\Column(name="ville", type="integer", nullable=true)
*/
private $ville;
/**
* #var string
*
* #ORM\Column(name="facebook", type="string", length=255, nullable=true)
*/
private $facebook;
/**
* #var string
*
* #ORM\Column(name="picture", type="string", length=255, nullable=true)
*/
private $picture;
/**
* #var integer
*
* #ORM\Column(name="newseltter", type="integer", nullable=true)
*/
private $newseltter;
/**
* #var \DateTime
*
* #ORM\Column(name="dateinscription", type="datetime", nullable=true)
*/
private $dateinscription;
/**
* #var \DateTime
*
* #ORM\Column(name="datedelete", type="datetime", nullable=true)
*/
private $datedelete;
/**
* #var string
*
* #ORM\Column(name="statut", type="string", length=50, nullable=true)
*/
private $statut;
/**
* #var string
*
* #ORM\Column(name="contenu", type="text", nullable=true)
*/
private $contenu;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set firstname
*
* #param string $firstname
* #return Client
*/
public function setFirstname($firstname)
{
$this->firstname = $firstname;
return $this;
}
/**
* Get firstname
*
* #return string
*/
public function getFirstname()
{
return $this->firstname;
}
/**
* Set lastname
*
* #param string $lastname
* #return Client
*/
public function setLastname($lastname)
{
$this->lastname = $lastname;
return $this;
}
/**
* Get lastname
*
* #return string
*/
public function getLastname()
{
return $this->lastname;
}
/**
* Set birthay
*
* #param \DateTime $birthay
* #return Client
*/
public function setBirthay($birthay)
{
$this->birthay = $birthay;
return $this;
}
/**
* Get birthay
*
* #return \DateTime
*/
public function getBirthay()
{
return $this->birthay;
}
/**
* Set mail
*
* #param string $mail
* #return Client
*/
public function setMail($mail)
{
$this->mail = $mail;
return $this;
}
/**
* Get mail
*
* #return string
*/
public function getMail()
{
return $this->mail;
}
/**
* Set phone
*
* #param string $phone
* #return Client
*/
public function setPhone($phone)
{
$this->phone = $phone;
return $this;
}
/**
* Get phone
*
* #return string
*/
public function getPhone()
{
return $this->phone;
}
/**
* Set pseudo
*
* #param string $pseudo
* #return Client
*/
public function setPseudo($pseudo)
{
$this->pseudo = $pseudo;
return $this;
}
/**
* Get pseudo
*
* #return string
*/
public function getPseudo()
{
return $this->pseudo;
}
/**
* Set password
*
* #param string $password
* #return Client
*/
public function setPassword($password)
{
$this->password = $password;
return $this;
}
/**
* Get password
*
* #return string
*/
public function getPassword()
{
return $this->password;
}
/**
* Set situation
*
* #param integer $situation
* #return Client
*/
public function setSituation($situation)
{
$this->situation = $situation;
return $this;
}
/**
* Get situation
*
* #return integer
*/
public function getSituation()
{
return $this->situation;
}
/**
* Set ville
*
* #param integer $ville
* #return Client
*/
public function setVille($ville)
{
$this->ville = $ville;
return $this;
}
/**
* Get ville
*
* #return integer
*/
public function getVille()
{
return $this->ville;
}
/**
* Set facebook
*
* #param string $facebook
* #return Client
*/
public function setFacebook($facebook)
{
$this->facebook = $facebook;
return $this;
}
/**
* Get facebook
*
* #return string
*/
public function getFacebook()
{
return $this->facebook;
}
/**
* Set picture
*
* #param string $picture
* #return Client
*/
public function setPicture($picture)
{
$this->picture = $picture;
return $this;
}
/**
* Get picture
*
* #return string
*/
public function getPicture()
{
return $this->picture;
}
/**
* Set newseltter
*
* #param integer $newseltter
* #return Client
*/
public function setNewseltter($newseltter)
{
$this->newseltter = $newseltter;
return $this;
}
/**
* Get newseltter
*
* #return integer
*/
public function getNewseltter()
{
return $this->newseltter;
}
/**
* Set dateinscription
*
* #param \DateTime $dateinscription
* #return Client
*/
public function setDateinscription($dateinscription)
{
$this->dateinscription = $dateinscription;
return $this;
}
/**
* Get dateinscription
*
* #return \DateTime
*/
public function getDateinscription()
{
return $this->dateinscription;
}
/**
* Set datedelete
*
* #param \DateTime $datedelete
* #return Client
*/
public function setDatedelete($datedelete)
{
$this->datedelete = $datedelete;
return $this;
}
/**
* Get datedelete
*
* #return \DateTime
*/
public function getDatedelete()
{
return $this->datedelete;
}
/**
* Set statut
*
* #param string $statut
* #return Client
*/
public function setStatut($statut)
{
$this->statut = $statut;
return $this;
}
/**
* Get statut
*
* #return string
*/
public function getStatut()
{
return $this->statut;
}
/**
* Set contenu
*
* #param string $contenu
* #return Client
*/
public function setContenu($contenu)
{
$this->contenu = $contenu;
return $this;
}
/**
* Get contenu
*
* #return string
*/
public function getContenu()
{
return $this->contenu;
}
}
?>
ClienFieldset
<?php
namespace Application\Form;
use Application\Entity\Client;
use Doctrine\Common\Persistence\ObjectManager;
use DoctrineModule\Stdlib\Hydrator\DoctrineObject as DoctrineHydrator;
use Zend\Form\Fieldset;
use Zend\InputFilter\InputFilterProviderInterface;
class ClientFieldset extends Fieldset implements InputFilterProviderInterface
{
public function __construct(ObjectManager $objectManager)
{
parent::__construct('post');
//$em = Registry::get('entityManager');
$this->setHydrator(new DoctrineHydrator($objectManager,'Application\Entity\Client'))
->setObject(new Client());
$this->setLabel('Post');
$this->add(array(
'name' => 'id',
'attributes' => array(
'type' => 'hidden'
)
));
$this->add(array(
'name' => 'mail',
'options' => array(
'label' => 'Title for this Post'
),
'attributes' => array(
'type' => 'text'
)
));
$this->add(array(
'name' => 'password',
'options' => array(
'label' => 'Text-Content for this post'
),
'attributes' => array(
'type' => 'text'
)
));
}
/**
* Define InputFilterSpecifications
*
* #access public
* #return array
*/
public function getInputFilterSpecification()
{
return array(
'mail' => array(
'required' => true,
'filters' => array(
array('name' => 'StringTrim'),
array('name' => 'StripTags')
),
'properties' => array(
'required' => true
)
),
'password' => array(
'required' => true,
'filters' => array(
array('name' => 'StringTrim'),
array('name' => 'StripTags')
),
'properties' => array(
'required' => true
)
)
);
}
}
?>
Client Form
<?php
namespace Application\Form;
use Doctrine\Common\Persistence\ObjectManager;
use DoctrineModule\Stdlib\Hydrator\DoctrineObject as DoctrineHydrator;
use Zend\Form\Form;
class ClientForm extends Form
{
public function __construct(ObjectManager $objectManager)
{
parent::__construct('post');
// The form will hydrate an object of type "BlogPost"
$this->setHydrator(new DoctrineHydrator($objectManager));
// Add the user fieldset, and set it as the base fieldset
$clientFieldset = new ClientFieldset($objectManager);
$clientFieldset->setUseAsBaseFieldset(true);
$this->add($clientFieldset);
$this->add(array(
'name' => 'security',
'type' => 'Zend\Form\Element\Csrf'
));
$this->add(array(
'name' => 'submit',
'attributes' => array(
'type' => 'submit',
'value' => 'Go',
'id' => 'submitbutton'
)
));
$this->setValidationGroup(array(
'security',
'post' => array(
'title',
'text'
)
));
}
}
?>
Index Action
<?php
public function indexAction()
{
$objectManager = $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');
// Create the form and inject the ObjectManager
$form = new ClientForm($objectManager);
// Create a new, empty entity and bind it to the form
$Client = new Client();
$form->bind($Client);
if ($this->request->isPost()) {
$form->setData($this->request->getPost());
if ($form->isValid()) {
$objectManager->persist($Client);
$objectManager->flush();
}
}
return array('form' => $form);
}
?>
#index View
<table class="table">
<?php
if($this->form){
echo $this->form()->openTag($form);
echo $this->formRow($form->get('id'));
echo $this->formRow($form->get('mail'));
echo $this->form()->closeTag();
}
</table> ?>
When i execute My Code i get this Error..
Warning:
include(/var/www/Colocation/Colocation/module/Visitor/config/../view/error/index.phtml):
failed to open stream: No such file or directory in
/var/www/Colocation/Colocation/vendor/zendframework/zendframework/library/Zend/View/Renderer/PhpRenderer.php
on line 506
Warning: include(): Failed opening '/var/www/Colocation/Colocation/module/Visitor/config/../view/error/index.phtml'
for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in
/var/www/Colocation/Colocation/vendor/zendframework/zendframework/library/Zend/View/Renderer/PhpRenderer.php
on line 506
Pleaz Help me!
The php warning says that it cannot find the file error/index.phtml.
It is looking for this file because somewhere in your code there is an error, which would lead to the error page.
Default error page files are located in the Application module (module/Application/view/error/), but in your case, it is trying to find these files in the 'Visitor' module.
Perhaps in the 'Visitor' module you overwritten the Application's module 'view_manager' configs, so you can try ONE of the follow:
Open the 'Visitor' module config file and comment or remove all error related configs, using this config for the 'view_manager' should be enough
'view_manager' => array(
'template_path_stack' => array(
'visitor' => __DIR__ . '/../view',
),
),
Create error page templates in your 'Visitor' module like the ones you can find in the Application module. Do this only if you want to customize your error page template, keeping unchanged the Application error template, otherwise use the first solution.
After you finish you should be able to see another error but this time related to your code!