Question.class.php
<?php
/**
* @author Richaud Julien "Fladnag"
*/
use salt\Base;
use salt\Field;
/**
* // @property annotations are used only for IDE autocomplete
* // there are not used by SALT framework
* @property int $id
* @property string $question
* @property boolean $response
*/
class Question extends Base {
public function metadata() {
parent::MODEL()
->registerId('id')
->registerTableName('questions')
->registerFields(
Field::newNumber('id', 'ID'),
Field::newText('question', 'Question', FALSE, 'Pourquoi ?'),
Field::newBoolean('response2', 'Réponse sans formatage'),
Field::newBoolean('response', 'Réponse')->displayOptions(array(
'type' => 'select',
'options' => array(
TRUE => 'Oui',
FALSE => 'Non',
),
'title' => 'Choisir une réponse',
))
);
}
}
displayOptions.php
<?php
/**
* @author Richaud Julien "Fladnag"
*/
define('TITLE', 'FORM booleen');
include('../../lib/base.php');
use salt\FormHelper;
use salt\ViewControl;
include(RELATIVE.'examples/dao/Question.class.php');
$q = new Question();
include(RELATIVE.'examples/layout/header.php');
ViewControl::edit();
?>
<div>
<?php if ($Input->G->ISSET->submit) { ?>
<b>Vous avez répondu :
<table class="compact">
<tr>
<th>Réponse sans formatage (response2)</th>
<th>Réponse (response)</th>
</tr>
<tr>
<td><?= var_dump($Input->G->RAW->response2) ?></td>
<td><?= var_dump($Input->G->RAW->response) ?></td>
</tr>
</table>
<?php
if ($Input->G->RAW->response == 42) {
echo '<a href="https://www.google.com/search?q=The+Hitchhiker\'s+Guide+to+the+Galaxy">42</a>';
}
?>
</b>
<br/>
<?php } ?>
<?= FormHelper::get() ?>
<div>
Question : <?= $q->VIEW->question ?><br/>
<br/>
<em>Un champ booléen non null ne peut valoir que 2 valeurs. Par défaut le framework SALT va donc mapper le champ sur une case à cocher :</em><br/>
Réponse sans formatage (response2) : <?= $q->FORM->response2 ?><br/>
<br/>
<em>Mais dans le cas du champ 'response', on a utilisé displayOptions pour afficher un select à la place :</em><br/>
Réponse (response) : <?= $q->FORM->response ?><br/>
<br/>
<?= FormHelper::input('submit', 'submit', 'Envoyer'); ?>
</div>
<?= FormHelper::end() ?>
</div>
<div>
<h3>Question.class.php</h3>
<?php highlight_file(RELATIVE.'examples/dao/Question.class.php'); ?>
<br/>
<h3><?= \salt\last(explode(DIRECTORY_SEPARATOR, __FILE__)) ?></h3>
<?php highlight_file(__FILE__); ?>
</div>
<?php include(RELATIVE.'examples/layout/footer.php');