cakephp 1.3 - Can't delete posts and can't add a post without an image -


i learning cakephp trying create note application. however, have 2 annoying bugs have stopped me going further , being able complete app.

edit: can see demo at: http://jeeremie.com (u: username / p: demo123 - can create new account if want).

i added option upload picture notes. uploader works fine if don't upload picture, cakephp tells me post has been added though don't see new note, neither on site or database. code add view is:

<!-- file: /app/views/notes/add.ctp -->  <h2>add note</h2> <hr /> <?php echo $form->create('note',array('type'=>'file')); echo $form->input('title', array( 'label' => 'enter title:' )); echo $form->input('body', array( 'label' => 'enter note:' ), array('rows' => '10')); echo $form->input('file',array('type' => 'file'), array( 'label' => 'attach file:' )); echo $form->input('id', array('type'=>'hidden')); echo '<hr />'; echo $form->end('save note'); ?> 

second, can't delete post though, again, tells me has been deleted post still remains. below code controller:

<!-- file: /app/controllers/notes_controller.php -->  <?php class notescontroller extends appcontroller {      var $name = 'notes';     var $components = array('auth', 'session');      var $paginate = array(         'limit' => 3,         'order' => array('note.modified' => 'desc')     );      function index() {         $condition = array('user_id'=>$this->auth->user('id'));         $this->set('notes', $this->paginate('note', $condition));         $this->helpers['paginator'] = array('ajax' => 'ajax');         //$this->set('notes', $this->note->find('all'));         //$this->note->recursive = 0;     }      function note($id = null) {         $this->note->id = $id;                 $this->set('note', $this->note->read());        }      function add() {         $this->layout = 'page';         if (!empty($this->data)) {             $this->data['note']['user_id'] = $this->auth->user('id');             if ($this->note->save($this->data['note']) == true) {                 $this->session->setflash('the note has been saved', 'flash_success');                 $this->redirect(array('action' => 'index'));             } else {                 $this->session->setflash('oops! note not saved. please, try again.', 'flash_error');             }         }     }      function delete($id) {         $this->note->delete($id);         $this->session->setflash('the note id: '.$id.' has been deleted.', 'flash_success');         $this->redirect(array('action'=>'index'));     }       function edit($id = null) {         $this->note->id = $id;         if (empty($this->data)) {             $this->data = $this->note->read();         } else {             if ($this->note->save($this->data)) {                 $this->session->setflash('your note has been updated.', 'flash_success');                 $this->redirect(array('action' => 'index'));             }         }     }   } ?> 

and last, notes view:

<!-- file: /app/views/notes/index.ctp --> <?php echo $html->link('add post',array('controller' => 'notes', 'action' => 'add'), array('class' => 'add'))?> <ul id="mynotes">    <?php foreach ($notes $note): ?>       <li>         <div class="thb">             <?php              //build img url             $base_url = $this->base;             $imgurl = $base_url . '/app/webroot/media/' . $note['note']['dirname'] . '/' . $note['note']['basename'];             //display thumb             if(!empty ($note['note']['file'])) {                 echo '<img class="thb" src="' . $imgurl . '" alt="' . $note['note']['title'] .'" />';              }             ?>         </div>         <h2><?php echo $html->link($text->truncate($note['note']['title'], 40), array('controller' => 'notes', 'action' => 'note', $note['note']['id'])); ?>         <span><?php echo $time->relativetime($note['note']['modified']); ?></span></h2>          <?php /* edit/delete button */ echo $html->link('edit', array('action'=>'edit', $note['note']['id'])) . ' | ' . $html->link('delete', array('action' => 'delete', $note['note']['id']), null, 'are sure?' ); ?>          <p>         <?php              $note = $note['note']['body'];             $noteurls = $text->autolink($note);             echo  $text->truncate($note, 120);         ?>         </p>      </li>  <?php endforeach; ?>  </ul> <!-- shows page numbers --> <?php echo $paginator->prev('« previous', null, null, array('class' => 'disabled')); ?> <?php echo $paginator->numbers(); ?> <?php echo $paginator->counter(); ?> <?php echo $paginator->next('next »', null, null, array('class' => 'disabled')); ?> 

does know problem here?

it seems not saving right. add function set flash message if:

$this->note->save($this->data['note']) == true 

i don't understand why trying save way...

why not save information user input in form this:

if($this->note->save($this->data)){ if success code goes here... } 

this take information input , save it. also, seem missing this:

$this->note->create(); 

did bake application or did code yourself?


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -