Consultez la FAQ sur le ZF avant de poster une question
Vous n'êtes pas identifié.
Bonjour,
<? php foreach ( $company as $companys ) : ?> < tr > < td > <? php echo $this ->escapeHtml( $companys ->site_id); ?> </ td > < td > <? php echo $this ->escapeHtml( $companys ->entity_code); ?> </ td > < td > <? php echo $this ->escapeHtml( $companys ->party_code); ?> </ td > < td > <? php echo $this ->escapeHtml( $companys ->party_name); ?> </ td > < td > <? php echo $this ->escapeHtml( $companys ->party_name2); ?> </ td > < td > <? php echo $this ->escapeHtml( $companys ->party_address); ?> </ td > < td > <? php echo $this ->escapeHtml( $companys ->party_address2); ?> </ td > < td > <? php echo $this ->escapeHtml( $companys ->party_zipcode); ?> </ td > < td > <? php echo $this ->escapeHtml( $companys ->party_city); ?> </ td > < td > <? php switch ( $companys ->party_country) { case 'BE' : echo $this ->translate( 'Belgium' ); break ; case 'SE' : echo $this ->translate( 'Sweden' ); break ; case 'IE' : echo $this ->translate( 'Italy' ); break ; case 'FR' : echo $this ->translate( 'France' ); break ; case 'GB' : echo $this ->translate( 'United Kingdom' ); break ; default : echo $this ->escapeHtml( $companys ->party_country); break ; } ?> </ td > < td > <? php echo $this ->escapeHtml( $companys ->systematic_consumption); ?> </ td > < td > <? php echo $this ->escapeHtml( $companys ->onsite_service_provided); ?> </ td > < td > <? php echo $this ->escapeHtml( $companys ->visible); ?> </ td > < td > <? php $url_edit = $this ->url( 'administrateur' , array ( 'action' => 'editcompany' , 'site_id' => $companys ->site_id)); ?> < a href=" <? php echo $url_edit ?> ">< i class = "fa fa-clipboard" ></ i > <?= $this ->translate( "Edit" ); ?> </ a > < br /> <? php $url_delete = $this ->url( 'administrateur' , array ( 'action' => 'deletecompany' , 'site_id' => $companys ->site_id)); ?> < a href=" <? php echo $url_delete ?> ">< i class = "fa fa-user-times" ></ i > <?= $this ->translate( "Delete" ); ?> </ a > </ td > </ tr > <? php endforeach ; ?> |
Mon problème est le suivant :
$url_delete = $this->url('administrateur', array('action'=>'deletecompany','site_id' =>$companys->site_id)); ?> < a href=" <? php echo $url_delete ?> ">< i class = "fa fa-user-times" ></ i > <?= $this ->translate( "Delete" ); ?> </ a > |
L'url n'envoie pas
'site_id' =>$companys->site_id |
est je ne comprend pas pourquoi ?
Voici mon controller :
public function deletecompanyAction() // Delete Company { $this ->layout( 'layout/admin' ); $site_id = (int) $this ->params()->fromRoute( 'site_id' , 0); if (! $site_id ) { \Zend\Debug\Debug::dump( $site_id ); //return $this->redirect()->toRoute('administrateur'); } else { $request = $this ->getRequest(); if ( $request ->isPost()) { $del = $request ->getPost( 'del' , 'No' ); if ( $del == 'Yes' ) { $site_id = (int) $request ->getPost( 'site_id' ); $this ->getCompanyTable()->deleteCompany( $site_id ); } return $this ->redirect()->toRoute( 'administrateur' ); } return array ( 'site_id' => $site_id , 'administrateur' => $this ->getCompanyTable()->getCompany( $site_id ) ); } } |
Et voici mon deletecompany.phtml :
<?php $title = $this ->translate( 'Delete Company' ); $this ->headTitle( $title ); ?> <h1><?php echo $this ->escapeHtml( $title ); ?></h1> <p><?= $this ->translate( 'Do you want to delete company' )?> '<?php echo $this->escapeHtml($this->party_name); ?>' ? </p> <?php $url = $this ->url( 'administrateur' , array ( 'action' => 'deletecompany' , 'site_id' => $this ->site_id, )); ?> <form action= "<?=$url?>" method= "post" > <div> <input type= "hidden" name= "site_id" value= "<?php echo (int) $company->site_id; ?>" /> <input type= "submit" name= "del" value= "Oui" /> <input type= "submit" name= "del" value= "Non" /> </div> </form> |
Pouvez vous m'aide à régler cette difficulté.
Si besoin d'autre donnée n'exister pas à demander.
J'ai pourtant repris le code du tutoriel sur Album de zf2.
Merci
Dernière modification par epcgroupe (15-02-2016 11:11:14)
Hors ligne
Bonjour je ne comprend pas ton code.... C'est con a dire mais je comprend pour d'ou tu viens dans le premier code posté, et ton $company->site_id de deletecompany.phtml n'existe tout simplement pas pour moi.
Hors ligne
Dans mon controller, j'appelle la première page (1er code)
public function indexcompanyAction() // Index Company { $this ->layout( 'layout/admin' ); return new ViewModel( array ( 'company' => $this ->getCompanyTable()->fetchAll(), )); } /////////////////////////// public function getCompanyTable() { if (! $this ->companyTable) { $sm = $this ->getServiceLocator(); $this ->companyTable = $sm ->get( 'Administrateur\Model\CompanyTable' ); } return $this ->companyTable; } |
Le fichier CompanyTable.php
<?php namespace Administrateur\Model; use Zend\Db\TableGateway\TableGateway; class CompanyTable { protected $tableGateway ; public function __construct(TableGateway $tableGateway ) { $this ->tableGateway = $tableGateway ; } public function fetchAll() { $resultSet = $this ->tableGateway->select(); return $resultSet ; } public function getCompany( $site_id ) { $site_id = (int) $site_id ; $rowset = $this ->tableGateway->select( array ( 'site_id' => $site_id )); $row = $rowset ->current(); if (! $row ) { throw new \Exception( "Could not find row $site_id" ); } return $row ; } public function saveCompany(Company $company ) { $data = array ( 'entity_code' => $company ->get_entity_code(), 'party_code' => $company ->get_party_code(), 'party_name' => $company ->get_party_name(), 'party_name2' => $company ->get_party_name2(), 'party_address' => $company ->get_party_address(), 'party_address2' => $company ->get_party_address2(), 'party_zipcode' => $company ->get_party_zipcode(), 'party_city' => $company ->get_party_city(), 'party_country' => $company ->get_party_country(), 'systematic_consumption' => $company ->get_systematic_consumption(), 'onsite_service_provided' => $company ->get_onsite_service_provided(), 'visible' => $company ->get_visible(), ); $site_id = (int) $company ->get_site_id(); if ( $site_id == 0) { $this ->tableGateway->insert( $data ); } else { if ( $this ->getCompany( $site_id )) { $this ->tableGateway->update( $data , array ( 'site_id' => $site_id )); } else { throw new \Exception( 'Company "id" does not exist' , 1); } } } public function deleteCompany( $site_id ) { $this ->tableGateway-> delete ( array ( 'site_id' => (int) $site_id )); } } |
Le fichier Company.php :
<?php namespace Administrateur\Model; use Zend\Validator\Identical; use Zend\InputFilter\InputFilter; use Zend\InputFilter\InputFilterAwareInterface; use Zend\InputFilter\InputFilterInterface; class Company // customer_site { public $site_id ; public $entity_code ; public $party_code ; public $party_name ; public $party_name2 ; public $party_address ; public $party_address2 ; public $party_zipcode ; public $party_city ; public $party_country ; public $systematic_consumption ; public $onsite_service_provided ; public $visible ; protected $inputFilter ; public function exchangeArray( $data ) { $this ->site_id = (! empty ( $data [ 'site_id' ])) ? $data [ 'site_id' ] : null; // no null $this ->entity_code = (! empty ( $data [ 'entity_code' ])) ? $data [ 'entity_code' ] : null; // no null $this ->party_code = (! empty ( $data [ 'party_code' ])) ? $data [ 'party_code' ] : null; // no null $this ->party_name = (! empty ( $data [ 'party_name' ])) ? $data [ 'party_name' ] : null; $this ->party_name2 = (! empty ( $data [ 'party_name2' ])) ? $data [ 'party_name2' ] : null; $this ->party_address = (! empty ( $data [ 'party_address' ])) ? $data [ 'party_address' ] : null; $this ->party_address2 = (! empty ( $data [ 'party_address2' ])) ? $data [ 'party_address2' ] : null; $this ->party_zipcode = (! empty ( $data [ 'party_zipcode' ])) ? $data [ 'party_zipcode' ] : null; $this ->party_city = (! empty ( $data [ 'party_city' ])) ? $data [ 'party_city' ] : null; $this ->party_country = (! empty ( $data [ 'party_country' ])) ? $data [ 'party_country' ] : null; // no null $this ->systematic_consumption = (! empty ( $data [ 'systematic_consumption' ])) ? $data [ 'systematic_consumption' ] : null; // no null $this ->onsite_service_provided = (! empty ( $data [ 'onsite_service_provided' ])) ? $data [ 'onsite_service_provided' ] : null; // no null $this ->visible = (! empty ( $data [ 'visible' ])) ? $data [ 'visible' ] : null; // no null } public function getArrayCopy() { return get_object_vars( $this ); } public function setInputFilter(InputFilterInterface $inputFilter ) { $er = $this ->translate( "Not used" ); throw new \Exception( $er ); } public function getInputFilter() { if (! $this ->inputFilter) { $inputFilter = new InputFilter(); $inputFilter ->add( array ( 'name' => 'site_id' , 'required' => true, 'filters' => array ( array ( 'name' => 'Int' ), ), )); $inputFilter ->add( array ( 'name' => 'party_code' , 'required' => true, 'filters' => array ( array ( 'name' => 'StripTags' ), array ( 'name' => 'StringTrim' ), ), 'validators' => array ( array ( 'name' => 'StringLength' , 'options' => array ( 'encoding' => 'UTF-8' , 'min' => 1, 'max' => 20, ), ), ), )); $inputFilter ->add( array ( 'name' => 'party_name' , 'required' => true, 'filters' => array ( array ( 'name' => 'StripTags' ), array ( 'name' => 'StringTrim' ), ), 'validators' => array ( array ( 'name' => 'StringLength' , 'options' => array ( 'encoding' => 'UTF-8' , 'min' => 1, 'max' => 100, ), ), ), )); $inputFilter ->add( array ( 'name' => 'party_address' , 'required' => true, 'filters' => array ( array ( 'name' => 'StripTags' ), array ( 'name' => 'StringTrim' ), ), 'validators' => array ( array ( 'name' => 'StringLength' , 'options' => array ( 'encoding' => 'UTF-8' , 'min' => 1, 'max' => 1000, ), ), ), )); $inputFilter ->add( array ( 'name' => 'party_zipcode' , 'required' => true, 'filters' => array ( array ( 'name' => 'StripTags' ), array ( 'name' => 'StringTrim' ), ), 'validators' => array ( array ( 'name' => 'StringLength' , 'options' => array ( 'encoding' => 'UTF-8' , 'min' => 1, 'max' => 20, ), ), ), )); $inputFilter ->add( array ( 'name' => 'party_city' , 'required' => true, 'filters' => array ( array ( 'name' => 'StripTags' ), array ( 'name' => 'StringTrim' ), ), 'validators' => array ( array ( 'name' => 'StringLength' , 'options' => array ( 'encoding' => 'UTF-8' , 'min' => 1, 'max' => 100, ), ), ), )); $inputFilter ->add( array ( 'name' => 'party_country' , 'required' => true, 'filters' => array ( array ( 'name' => 'StripTags' ), array ( 'name' => 'StringTrim' ), ), 'validators' => array ( array ( 'name' => 'StringLength' , 'options' => array ( 'encoding' => 'UTF-8' , 'min' => 1, 'max' => 2, ), ), ), )); $this ->inputFilter = $inputFilter ; } return $this ->inputFilter; } function get_site_id() { return $this ->site_id; } function set_site_id( $site_id ) { $this ->site_id = $site_id ; } function get_entity_code() { return $this ->entity_code; } function set_entity_code( $entity_code ) { $this ->entity_code = $entity_code ; } function get_party_code() { return $this ->party_code; } function set_party_code( $party_code ) { $this ->party_code = $party_code ; } function get_party_name() { return $this ->party_name; } function set_party_name( $party_name ) { $this ->party_name = $party_name ; } function get_party_name2() { return $this ->party_name2; } function set_party_name2( $party_name2 ) { $this ->party_name2 = $party_name2 ; } function get_party_address() { return $this ->party_address; } function set_party_address( $party_address ) { $this ->party_address = $party_address ; } function get_party_address2() { return $this ->party_address2; } function set_party_address2( $party_address2 ) { $this ->party_address2 = $party_address2 ; } function get_party_zipcode() { return $this ->party_zipcode; } function set_party_zipcode( $party_zipcode ) { $this ->party_zipcode = $party_zipcode ; } function get_party_city() { return $this ->party_city; } function set_party_city( $party_city ) { $this ->party_city = $party_city ; } function get_party_country() { return $this ->party_country; } function set_party_country( $party_country ) { $this ->party_country = $party_country ; } function get_systematic_consumption() { return $this ->systematic_consumption; } function set_systematic_consumption( $systematic_consumption ) { $this ->systematic_consumption = $systematic_consumption ; } function get_onsite_service_provided() { return $this ->onsite_service_provided; } function set_onsite_service_provided( $onsite_service_provided ) { $this ->onsite_service_provided = $onsite_service_provided ; } function get_visible() { return $this ->visible; } function set_visible( $visible ) { $this ->visible = $visible ; } } ?> |
Dernière modification par epcgroupe (03-02-2016 14:41:24)
Hors ligne
Le $companys->site_id existe bien pour la simple raison que je l'affiche sans problème quand je met ce code juste avant $urldelete.
\Zend\Debug\Debug::dump( $companys ->site_id); |
Dernière modification par epcgroupe (03-02-2016 14:46:22)
Hors ligne
Mais pas dans l'url ,quand je met :
$url_delete = $this ->url( 'administrateur' , array ( 'action' => 'deletecompany' , 'site_id' => $companys ->site_id));?> \Zend\Debug\Debug::dump( $url_delete ); |
Si tu peux me dépanner la dessus.
J'en remercie.
Dernière modification par epcgroupe (03-02-2016 14:48:04)
Hors ligne
Hello,
Alors c'est sans doute très con comme réponse, mais tu n'aurais pas un problème de caractère invisible dans ta variable? ^^'
à priori quand tu colle la ligne de ton url ça bug sur le companys...
Ps: c'est chiant je sais mais.. vu que ton post est en zf2, essai de le poster dans la bonne partie du fofo
(même si tu l'écris dans le titre ^^)
Hors ligne
oups, oui je me suis tromper de fofo... désolé
Hors ligne
Je n'ai rien trouvé de particulier dans la variable en caractère spéciale ou caché.
Hors ligne
Bonjour,
Une question comment est configuré ta route administrateur ?
Hors ligne
module.config :
return array ( 'controllers' => array ( 'invokables' => array ( 'Administrateur\Controller\Administrateur' => 'Administrateur\Controller\AdministrateurController' , ), ), 'router' => array ( 'routes' => array ( 'administrateur' => array ( 'type' => 'segment' , 'options' => array ( 'route' => '/administrateur[/:action][/:id]' , 'constraints' => array ( 'action' => '[a-zA-Z][a-zA-Z0-9_-]*' , 'id' => '[0-9]+' , ), 'defaults' => array ( 'controller' => 'Administrateur\Controller\Administrateur' , 'action' => 'index' , ), ), ), ), ), 'view_manager' => array ( 'template_path_stack' => array ( 'administrateur' => __DIR__ . '/../view' , ), ), ); |
Dernière modification par epcgroupe (04-02-2016 10:52:47)
Hors ligne
'site_id' =>$companys->site_id
site_id mmhh??
Hors ligne
J'ai un peu repris le tuto du site Zend 2 avec Album :
<? php // module/Album/view/album/album/index.phtml: $title = 'My Album' ; $this ->headTitle( $title ); ?> < h1 > <? php echo $this ->escapeHtml( $title ); ?> </ h1 > < p > < a href=" <? php echo $this ->url( 'album' , array ( 'action' => 'add' )); ?> ">Add new album</ a > </ p > < table class = "table" > < tr > < th >Title</ th > < th >Artist</ th > < th > </ th > </ tr > <? php foreach ( $albums as $album ) : ?> < tr > < td > <? php echo $this ->escapeHtml( $album ->title); ?> </ td > < td > <? php echo $this ->escapeHtml( $album ->artist); ?> </ td > < td > < a href=" <? php echo $this ->url( 'album' , array ( 'action' => 'edit' , 'id' => $album ->id)); ?> ">Edit</ a > < a href=" <? php echo $this ->url( 'album' , array ( 'action' => 'delete' , 'id' => $album ->id)); ?> ">Delete</ a > </ td > </ tr > <? php endforeach ; ?> </ table > |
Hors ligne
oui mais regarde ta route :
'/administrateur[/:action][/:id]' |
Elle attend un paramètre "action" et "id" mais tu lui donne "site_id", qu'elle ne peut pas comprendre
Dernière modification par flobrflo (04-02-2016 11:00:43)
Hors ligne
J'ai changé les routes est :
'/administrateur[/:action][/:id]' '/administrateur[/:action][/:site_id]' '/administrateur[/:action][/:id][/:site_id]' |
Est cela ne marche toujours pas.
Hors ligne
peut tu remontrer les routes complète? ^^
Hors ligne
Oui pas de problème :
Dans le module.config :
return array ( 'controllers' => array ( 'invokables' => array ( 'Administrateur\Controller\Administrateur' => 'Administrateur\Controller\AdministrateurController' , ), ), 'router' => array ( 'routes' => array ( 'administrateur' => array ( 'type' => 'segment' , 'options' => array ( 'route' => '/administrateur[/:action][/:id][/:site_id]' , 'constraints' => array ( 'action' => '[a-zA-Z][a-zA-Z0-9_-]*' , 'id' => '[0-9]+' , ), 'defaults' => array ( 'controller' => 'Administrateur\Controller\Administrateur' , 'action' => 'index' , ), ), ), ), ), 'view_manager' => array ( 'template_path_stack' => array ( 'administrateur' => __DIR__ . '/../view' , ), ), ); |
Dans mon index :
<? php foreach ( $company as $companys ) : ?> < td > <? php $url_edit = $this ->url( 'administrateur' , array ( 'action' => 'editcompany' , 'site_id' => $companys ->site_id)); ?> < a href=" <? php echo $url_edit ?> ">< i class = "fa fa-clipboard" ></ i > <?= $this ->translate( "Edit" ); ?> </ a > < br /> <? php $url_delete = $this ->url( 'administrateur' , array ( 'action' => 'deletecompany' , 'site_id' => $companys ->site_id)); ?> < a href=" <? php echo $url_delete ?> ">< i class = "fa fa-user-times" ></ i > <?= $this ->translate( "Delete" ); ?> </ a > </ td > </ tr > <? php endforeach ; ?> |
Voilà !
Hors ligne
Oui donc actuellement il te manque le paramètre id pour ta route ^^
Hors ligne
ah ça fonctionne pas en OU mais en ET : Ok. je test.
Hors ligne
Oui c'est dans l'ordre et surtout tu a rajouté une contrainte à ton id :
'id' => '[0-9]+' , |
1 ou plusieurs chiffres ^^
Hors ligne
Peut tu m'expliquer comment ça fonctionne, je me suis auto formée seul avec juste le site en anglais. Et je suis pas trop en forme sur l'anglais .
Si ça te dérange pas ?
Hors ligne
Mmmmhhh...
Je t'invite à chercher un petit peu dans le forum, Orkin a déjà fait une belle réponse dans un sujet similaire il y a quelques temps ^^
Mais en gros ton url de type segment que tu a montré 2 messages plus tôt va correspondre aux urls de type:
/administrateur
/administrateur[/:action]
/administrateur[/:action][/:id]
/administrateur[/:action][/:id][/:site_id]
Sauf que par dessus tu rajoute des contraintes de type
'id' => '[0-9]+',
qui rendent obligatoire ton paramètre id car il faut au moins 1 chiffre pour "passer" ta contrainte
Dernière modification par flobrflo (05-02-2016 13:53:05)
Hors ligne
Mon erreur n'étais pas que dans les routes.
J'ai retirer la contrainte dans la route.
J'ai retirer deux erreurs de saisie dans le controller.
Merci de votre coup de main.
Hors ligne