Salut, j'ai un problème lorsque je fais éditer un article . Si il y a id de l'article elle fonction mais si je fais un id cacher (hidden) par se url:http://localhost/Site/cockpit/posts/edit/ un erreur s'affiche "Notice: Trying to get property of non-object in C:\wamp1\www\Site\Core\Form.php on line 33" je fais un debug(this->controller->request); dans ma Form .php il m'affiche: C:\wamp1\www\Site\Core\Form.php l .10 C:\wamp1\www\Site\Core\Dispatcher.php l.39 C:\wamp1\www\Site\Core\Dispatcher.php l.9 C:\wamp1\www\Site\Webroot\index.php l.10 Request Object ( [url] => /cockpit/posts/edit/ [page] => 1 [prefix] => admin [data] => [controller] => posts [action] => edit [params] => Array ( ) ) et lorsque je tape debug(this->request->data); dans mon PostController aucun affichage aussi si je tape debug($sql); dans la fonction de save dans Model.php aucun affichage es-que le probléme et du variable "data" [code]<?php /**
-
*/
class Form
{
public controller;
public function __construct(controller){
this->controller=controller; debug(this->controller->request); } public function input(name,label,options=array()){ if (label == 'hidden') { return '<input type="hidden" name="'.name.'" value="'.this->controller->request->data->name.'">'; } $html='
<label for="input'.name.'">'.label.'</label>
'; attr=' '; foreach (options as k => $v) { if (k!='type') { # code... attr .= " $k=\"v\""; }} if (!isset(options['type'])) { $html.='<input type="text" id="input'.name.'" name="'.name.'" value="'.this->controller->request->data->name.'">'; }elseif (options['type']=='textarea') { html.='<textarea id="input'.name.'" name="'.name.'">'.this->controller->request->data->name.'</textarea>'; }elseif (options['type']=='checkbox') { html.='<input type="hidden" name="'.name.'" value="0"><input type="checkbox" name="'.$name.'" value="1">'; } $html .='
'; return $html; } } ?>[/code] admin_edit.php [code]
Editer Un Article
<form action="<?php%20echo%20Router::url('admin/posts/edit/');%20%20?>" method="post">
<?php echo $this->Form->input('name','Titre') ;?>
<?php echo $this->Form->input('slug','Url') ;?>
<?php echo $this->Form->input('id','hidden'); ?>
<?php echo $this->Form->input('content','contenu',array('type'=>'textarea','class'=>'xxlarge','rows'=>5)); ?>
<?php echo $this->Form->input('online','En ligne',array('type'=>'checkbox')); ?>
<div class="action">
<input type="submit" class="btn primary" value="Envoyer">
</div>
</form>[/code] PostsController [code]//permet d'editer un article function admin_edit(id = null){ $this->loadModel('Post'); if (this->request->data) { this->Post->save(this->request->data); // debug(this->request->data); } $this->request->data=this->Post->findFirst(array( 'conditions'=>array('id'=>id) )); }[/code] Model.php [code]public function save(data){ key=this->primarykey; fields=' '; foreach (data as k => $v) { $fields .= " $k=:k"; } if (isset(data->key) && !empty(data->key)) { sql='UPDATE '.this->table.' SET '.fields.' WHERE '.key.'=:'.key; } debug(sql); die(); } [/code] merci en avence