CakePHP : Componsant 'Security' et $form->input
Par foxmask le mardi, février 19 2008, 21:08 - Lien permanent
Dans la "Vue", quand le componsant Security est 'activé (aka public $component = array('Security') dans notre controleur ), il n'y a pas moyen de contourner l'utilisation de $form->create $form->end et surtout $form->input. Si vous vous contentez de $form->create / end et codez vos input "à la main" (sans utiliser $form-> ) alors aucune chance pour que 'Security' vous laisse "passer" .
Ainsi donc ceci ne fonctionne pas pour la raison évoqué à l'instant :
<?php echo $form->create('Themes',array('action'=>'admin_save'));?>
<p><?php echo __('Choose the theme to use on your portal.'); ?></p>
<div class="two-cols">
<?php
$d = dir(PUNCAKE_THEMES_PATH);
while (($entry = $d->read()) !== false)
{
if ($entry != '.' && $entry != '..' && $entry != '.svn'
&& is_dir(PUNCAKE_THEMES_PATH.DS.$entry)
&& file_exists(PUNCAKE_THEMES_PATH.DS.$entry.'/__infos.php'))
{
$theme_infos = array(
'name' => '',
'desc' => array(),
'author' => '',
'version' => '',
'preview' => ''
);
require PUNCAKE_THEMES_PATH.DS.$entry.'/__infos.php';
?>
<div class="col">
<h3>
<input type="radio" name="data[Themes][pt_theme]" value="<?php echo
$entry;?>" <?php echo ($pt_theme==$entry) ? "checked=\"checked\"" :
''; ?>/>
<label for="<?php echo $entry ?>"><?php echo $theme_infos['name']?
><?php echo (!empty($theme_infos['version']) ? ' (v'.
$theme_infos['version'].')' : '')?>
</label></h3>
<p class="field">
<?php echo (!empty($theme_infos['preview']) ? '<label for="'.
$entry.'"><img id="'.$entry.'" src="'.pt_portal_url.'themed/'.
$entry.'/'.$theme_infos['preview'].'" alt="" /></label>' : '') ?>
<span class="desc"><?php echo __('by',true).' '.
$theme_infos['author'] ?></span></p>
<?php echo (!empty($theme_infos['desc'][$user['language']]) ? '<p>'.
$theme_infos['desc'][$user['language']].'</p>' : (!
empty($theme_infos['desc']['English']) ? '<p>'.$theme_infos['desc']
['English'].'</p>' : ''))?>
</div>
<?php
}
}
$d->close(); ?>
</div>
<?php echo $form->submit( __('Save',true) ,array('class'=>'submit'))?>
<?php echo $form->end(); ?>
Pour obtenir exactement le même code html mais qui satisfasse le composant 'Security' il faut la jouer comme ceci :
<?php echo $form->create('Themes',array('action'=>'admin_save'));?>
<p><?php echo __('Choose the theme to use on your portal.'); ?></p>
<div class="two-cols">
<?php
$d = dir(PUNCAKE_THEMES_PATH);
while (($entry = $d->read()) !== false)
{
if ($entry != '.' && $entry != '..' && $entry != '.svn'
&& is_dir(PUNCAKE_THEMES_PATH.DS.$entry)
&& file_exists(PUNCAKE_THEMES_PATH.DS.$entry.'/__infos.php'))
{
$theme_infos = array(
'name' => '',
'desc' => array(),
'author' => '',
'version' => '',
'preview' => ''
);
require PUNCAKE_THEMES_PATH.DS.$entry.'/__infos.php';
$version = (!empty($theme_infos['version']) ? ' (v'.
$theme_infos['version'].')' : '');
$before = '<div class="col">'."\n";
$before .= '<h3>'."\n";
$after = '';
$after .= '</h3>';
$after .= '<p class="field">'."\n";
$after .= (!empty($theme_infos['preview']) ? '<label
for="'.$entry.'"><img id="'.$entry.'" src="'.pt_portal_url.'themed/'.
$entry.'/'.$theme_infos['preview'].'" alt="" /></label>' :
'');
$after .= '<span class="desc">'. __('by',true).' '.
$theme_infos['author'] .'</span></p>'."\n";
$after .= (!empty($theme_infos['desc']
[$user['language']]) ? '<p>'.$theme_infos['desc']
[$user['language']].'</p>' : (!empty($theme_infos['desc']
['English']) ? '<p>'.$theme_infos['desc']['English'].'</p>' : ''));
$after .= '</div>'."\n";
echo $form->input('pt_theme',
array(
'div'=>false,
'label'=>true,
'legend'=>false,
'type'=>'radio',
'before' => $before,
'after' => $after,
'value' => $pt_theme,
'options'=> array($entry=>$theme_infos['name'].
$version)
)
);
}
}
$d->close(); ?>
</div>
<?php echo $form->submit( __('Save',true) ,array('class'=>'submit'))?
<?php echo $form->end(); ?>