Anciennes révisionsLiens de retourExporter en PDFHaut de page Share via Share via... Twitter LinkedIn Facebook Pinterest Telegram WhatsApp Yammer RedditDerniers changementsSend via e-MailImprimerPermalien × Concrete5: blocks / db / CRUD Doc Custom Objects Demo, http://www.concrete5.org/marketplace/addons/custom-objects-demo/, free kind of a 'learning' package Boilerplate CRUD (Dashboard Interface for non-page data), https://github.com/jordanlev/c5_boilerplate_crud (automobiles / ex. base relationelle) Using custom objects and lists to create concrete5 dashboard pages and front end search pages, http://www.werstnet.com/blog/using-custom-objects-and-lists-to-create-concrete5-dashboard-pag/ (local copy) : lier à la tables des utilisateurs, changer la vue, prévoir une liste de pages Objectif: créer un bloc “Acteurs” = une table “Acteurs” avec possibilité de lister, voir, ajouter, modifier et effacer (aka CRUD); la table acteurs comprend des informations sur les personnes qui la peuplent, avec aussi une image extraite de la bibliothèque d'images c5 Astuce: pour développer un bloc c5 il faut travailler en MVC (Model-View-Controller) créer le bloc créer sous le répertoire blocks/ le répertoire actors mkdir blocks/actor Dans ce répertoire, créer les fichiers suivants: add.php controller.php db.xml edit.php form_setup_html.php view.php action: cd actor touch add.php controller.php db.xml edit.php form_setup_html.php view.php modèle: db.xml le fichier qui définit la table de la base de données (model) http://phplens.com/lens/adodb/docs-datadict.htm#xmlschema exemple: <?xml version="1.0"?> <schema version="0.3"> <table name="btActor"> <field name="bID" type="I"> <key/> <unsigned/> </field> <field name="firstname" type="C" size="255"></field> <field name="lastname" type="C" size="255"></field> <field name="title" type="C" size="255"></field> <field name="position" type="X"></field> <field name="phone" type="C" size="255"></field> <field name="fax" type="C" size="255"></field> <field name="email" type="C" size="255"></field> <field name="website" type="X"></field> <field name="fIDpicture" type="I"></field> <field name="description" type="X2"></field> </table> </schema> correspondra à la table MySQL -- -- Table structure for table `btActor` -- CREATE TABLE IF NOT EXISTS `btActor` ( `bID` INT(10) UNSIGNED NOT NULL, `firstname` VARCHAR(255) DEFAULT NULL, `lastname` VARCHAR(255) DEFAULT NULL, `title` VARCHAR(255) DEFAULT NULL, `position` text, `phone` VARCHAR(255) DEFAULT NULL, `fax` VARCHAR(255) DEFAULT NULL, `email` VARCHAR(255) DEFAULT NULL, `website` text, `fIDpicture` INT(11) DEFAULT NULL, `description` longtext PRIMARY KEY (`bID`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; contrôleur:controller.php <?php defined('C5_EXECUTE') or die('Access Denied. '); class ActorBlockController extends BlockController { protected $btTable = 'btActor'; protected $btInterfaceWidth = '600'; protected $btInterfaceHeight = '600'; protected $btCacheBlockRecord = true; protected $btCacheBlockOutput = true; protected $btCacheBlockOutputOnPost = true; protected $btCacheBlockOutputForRegisteredUsers = true; protected $btCacheBlockOutputLifetime = CACHE_LIFETIME; public function getBlockTypeDescription() { return t("Profil d'un acteur"); } public function getBlockTypeName() { return t("Acteur"); } public function view() { $this->set('bID', $this->bID); $this->set('picture', $this->getPicture()); } public function save($data) { parent::save($data); } public function getPicture() { if ($this->fIDpicture > 0) { return File::getByID($this->fIDpicture); } return null; } } on a défini dans le contrôleur les différentes méthodes vues add.php et edit.php sont de simples synonymes du fichier form_setup_html.php: add.php <?php defined('C5_EXECUTE') or die('Access Denied.'); $this->inc('form_setup_html.php'); edit.php <?php defined('C5_EXECUTE') or die('Access Denied.'); $this->inc('form_setup_html.php'); form_setup_html.php <?php defined('C5_EXECUTE') or die('Access Denied.'); $al = Loader::helper('concrete/asset_library'); ?> <div class="ccm-block-field-group"> <b><?php echo $form->label('fIDpicture', t('Photo'))?></b> <?php echo $al->image('ccm-b-image', 'fIDpicture', t('Choose File'), $this->controller->getPicture()); ?> </div> <div class="ccm-block-field-group"> <table> <tr> <td> <b><?php echo $form->label('title', t('Title'))?></b><br/> <?php echo $form->text('title', $title, array('style' => 'width: 60px'));?> </td> <td> <b><?php echo $form->label('firstname', t('Firstname'))?></b><br/> <?php echo $form->text('firstname', $firstname, array('style' => 'width: 220px'));?> </td> <td> <b><?php echo $form->label('lastname', t('Lastname'))?></b><br/> <?php echo $form->text('lastname', $lastname, array('style' => 'width: 220px'));?> </td> </tr> <tr> <td colspan="3"> <b><?php echo $form->label('position', t('Position'))?></b><br/> <?php echo $form->text('position', $position, array('style' => 'width: 100%'));?> </td> </tr> <tr> <td colspan="3"> <b><?php echo $form->label('email', t('E-mail'))?></b><br/> <?php echo $form->text('email', $email, array('style' => 'width: 100%'));?> </td> </tr> <tr> <td colspan="2"> <b><?php echo $form->label('phone', t('Phone'))?></b><br/> <?php echo $form->text('phone', $phone, array('style' => 'width: 200px'));?> </td> <td> <b><?php echo $form->label('fax', t('Fax'))?></b><br/> <?php echo $form->text('fax', $fax, array('style' => 'width: 200px'));?> </td> </tr> <tr> <td colspan="3"> <b><?php echo $form->label('website', t('Website'))?></b><br/> <?php echo $form->text('website', $website, array('style' => 'width: 100%'));?> </td> </tr> </table> </div> <div class="ccm-block-field-group"> <b><?php echo $form->label('description', t('Description'))?></b> <?php Loader::element('editor_config'); Loader::element('editor_controls', array('mode' => 'full')); echo $form->textarea('description', $description, array('class' => 'ccm-advanced-editor')); ?> </div> view.php <?php defined('C5_EXECUTE') or die('Access Denied.'); $html = Loader::helper('html'); $ih = Loader::helper('image'); $v = View::getInstance(); ?> <div class="teamBlock"> <div class="teamImg"> <?php if ($picture instanceof File) { $thumb = $ih->getThumbnail($picture, 100, 150); echo $html->image($thumb->src, array('width'=> $thumb->width, 'height' => $thumb->height)); } else { echo $html->image($this->getThemePath()."/images/default_head.png"); } ?> </div> <div class="teamText"> <p> <b> <span><?php echo $title ?></span> <span><?php echo $firstname ?></span> <span><?php echo $lastname ?></span> </b> <br/> <span><?php echo $position ?></span> <br/> <?php if ($phone != '') { echo sprintf("<span>%s : %s</span><br/>", t('Phone'), $phone); } if ($fax != '') { echo sprintf("<span>%s : %s</span><br/>", t('Fax'), $fax); } if ($email != '') { echo sprintf("<span><a href=\"mailto:%s\">%s</a></span><br/>", $email, t('E-mail')); } if ($website != '') { echo sprintf("<span><a href=\"%s\" target=\"_blank\" class=\"www\">%s</a></span><br/>", $website, $website); } ?> </p> </div> <div class="floatleftclear"><!-- --></div> <div class="solidline"><!-- --></div> </div> <div> <?php echo $description ?> </div> info/concrete5/docfred/blocks.txt Dernière modification : 2018/07/18 10:28de 176.9.50.244 S'identifier