I am trying to create a saveAction in zend2 framework using doctrine.
in my PromotionsController i have this action:
public function saveLinkAction() {
$view = new ViewModel();
$salonId = (int) $this->params()->fromPost('salon_id', null);
$addLink = $this->getServiceLocator()->get('Promotions\Model\Link');
$linkData['salon_id'] = $salonId;
$linkData['link'] = '/link/example';
$addLink->setData($linkData);
return $view;
}
This is just for learning how to write data in database.
$addLink = $this->getServiceLocator()->get('Promotions\Model\Link');
This line of code is showing an error and i don't know what is the cause?
Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for Promotions\Model\Link
I have created a Link.php in Model directory.
<?php
namespace Link\Model;
use Application\Model\Entity;
use Zend\Form\Annotation;
/**
* @Entity
* @Table(name="promo_link")
*/
class Link extends Entity {
/********** PROPERTIES **********/
/**
* @Id @GeneratedValue(strategy="AUTO") @Column(name="id", type="integer")
* @var int
*
* @Annotation\Exclude()
*/
protected $id;
/**
* @Column(name="salon", type="integer")
* @var int
*
* @Annotation\Options({"label":"Salon"})
* @Annotation\Validator({"name": "Digits"})
*/
protected $salon;
/**
* @Column(name="link", type="string")
* @var string
*/
protected $link;
/**
* @Column(name="start_date", type="string")
* @var string
*/
protected $start_date;
/**
* @Column(name="end_date", type="string")
* @var string
*/
protected $end_date;
}
?>