array('role'=>array('Admin','Author')), 'edit' => array('role'=>array('Admin','Author')), 'delete' => array('role'=>array('Admin')) ); function edit($id=null) { $cat = $this->_flattenArray($this->Category->query ('select id, title from categories')); $selected = $this->_flattenArray( $this->Post->query('SELECT category_id FROM categories_posts WHERE post_id = '. $id)); foreach($cat as $key => $value): if (! ($key % 2)): $categories[$value] = $cat[$key + 1]; endif; endforeach; $this->set('categories', $categories); $this->set('selected', $selected); // $this->set('css_array',array($this->rdTheme.'/form',$this->rdTheme.'/view')); $this->Post->id = $id; if (empty($this->data)) { $this->data = $this->Post->read(); //converting nl2br back so it looks better $this->Output->br2nl($this->data); $this->render(); } else { //set the user id $this->data['Post']['user_id'] = $this->rdAuth->id; //make sure data is clean $this->Output->filter($this->data); $this->Sanitize->cleanArray($this->data); if ($this->Post->save($this->data)) { $this->action = 'index'; $this->set('message','post edited. click publish to allow immediate viewing.'); $this->index(); $this->render('index'); } else { //converting nl2br back so it looks better $this->Output->br2nl($this->data); $this->render(); } } } ?>

formTag('/posts/edit')?> hidden('Post/id');?>
Edit Post
required
input('Post/title',array('class'=>'expanding'));?> tagErrorMsg('Post/title', '*required*');?>
 
required
selectTag('Category/title', $categories, $selected, array('multiple' => 'multiple')) ?> tagErrorMsg('Category/title', '*required*');?>
 
required, html help tagErrorMsg('Post/article', '*required*')?>
textarea('Post/body',array('class'=>'expanding'))?>
 
submit('Save') ?>