Catchable fatal error: Object of class Application_Model_DbTable_Service could not be converted to string
Bonjour,
j'ai un petit soucis d'insertion.
Puis je avoir un peu d'aide s'il vous plaît?
j'ai l'erreur suivante :
Catchable fatal error: Object of class Application_Model_DbTable_Service could not be converted to string in /usr/local/zend/share/ZendFramework/library/Zend/Db/Statement/Pdo.php on line 228
Voici mon Db_table :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
protected $_name = 'service';
protected $_primary = 'id'; // genre id_****
protected $_dependentTables = array('Deviceservice');
public function lireTout(){
$select = $this->select()
->setIntegrityCheck(false)
->from(array('s' => 'service'),
array('name','link_description','enable'));
$result = $this->fetchAll($select);
return $result->toArray();
}
public function ajouterService($service, $description, $enable)
{
$data = array(
'name' => $service,
'link_description' => $description,
'enable' => $enable,
);
$this->insert($data);
} |
et mon controller:
Code:
1 2 3 4
|
$model = new Application_Model_DbTable_Service();
$this->view->service = $model->ajouterService(); |
La clé primaire de service est transmise à la table device_service:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
protected $_name = 'device_service';
protected $_primary = 'id';
protected $_referenceMap = array(
'Reporter' => array(
'columns' => 'id',
'refTableClass' => 'Service',
'refColumns' => 'id'
)
);
protected $_referenceMap = array(
'Reporter' => array(
'columns' => 'id',
'refTableClass' => 'Device',
'refColumns' => 'id'
)
); |
merci d'avance de votre aide.
Cordialement,
problème insertion null zend php 5
re bonjour,
j'ai corrigé certaines choses.
Mon problème est que j'insers des valeurs NULL.
Pourriez vous me donne run coup de main s'il vous plaît ?
Mon formulaire:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
class Application_Form_Ajoutservice extends Zend_Form
{
public function init()
{
/* Form Elements & Other Definitions Here ... */
$id = new Zend_Form_Element_Hidden('id');
$service = new Zend_Form_Element_Text('name');
$service->setLabel('Service')
->setRequired(true)
->addFilter('StringTrim')
->addValidator('NotEmpty');
$description = new Zend_Form_Element_Text('link_description');
$description->setLabel('Description')
->setRequired(true)
->addFilter('StringTrim')
->addValidator('NotEmpty');
$enable = new Zend_Form_Element_Checkbox('enable');
$enable->setLabel('Cochez si actif');
$envoyer = new Zend_Form_Element_Submit('envoyer');
$envoyer->setAttrib('id', 'boutonenvoyer');
$this->addElements(array($id,$service,$description,$enable,$envoyer));
}
} |
mon controller :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
public function ajouterserviceAction()
{
// action body
Zend_Layout::getMvcInstance()->setLayout('layoutajoutserv');
$form = new Application_Form_Ajoutservice();
$form->setAction('http://6.0.0.40/WebMRL/public/index.php/configuration/consulterunservice')
->setMethod('post');
$form->envoyer->setLabel('Ajouter');
$this->view->form = $form;
if ($this->getRequest()->isPost()) {
$formData = $this->getRequest()->getPost();
if ($form->isValid($formData)) {
$service = $form->getValue('name');
$description = $form->getValue('link_description');
$enable = $form->getValue('enable');
$service = new Application_Model_DbTable_Service();
$service->ajouterService($service,$description,$enable);
$this->_redirect('/');
} else {
$form->populate($formData);
}
}
} |
mon model :
Code:
1 2 3 4 5 6 7 8 9 10 11 12
|
public function ajouterService($service,$description,$enable)
{
$data = array(
'name' => $service,
'link_description' => $description,
'enable' => $enable,
);
$this->insert($data);
} |
merci d'avance de votre aide.
Cordialement,