Problems adding action in Zend Framework 1

0

I'm having trouble adding a song that's contained in the album, so when I add a song it's already related to the album id.

My problem is in the addMusic () method below:

MusicasController:

public function adicionarAction() {
    $forms = new Application_Form_FormMusicas();
    $forms->submit->setLabel('Adicionar');
    $this->view->form = $forms;

    if ($this->getRequest()->isPost()) {
        $formData = $this->getRequest()->getPost();
        if ($forms->isValid($formData)) {

            $idmusica = $forms->getValue('idmusica');

            $musica = $forms->getValue('musica');
            $duracao = $forms->getValue('duracao');

            $musicas = new Application_Model_DbTable_Musicas();
            $musicas->adicionarMusica($musica, $duracao, $idmusica);

            $this->_helper->redirector('index', 'idmusica');
        } else {
            $forms->populate($formData);
        }
    }
}

Here is some other information that might help with the help:

Database:

Tables:

- albums -

id INT PRIMARY KEY

artist varchar (40)

title varchar (40)

- music -

id INT PRIMARY KEY

VARCHAR music (40)

duration varchar (40)

idmusica int FOREIGN KEY for albums (id)

Application_Model_DbTable_Musicas:

  protected $dbt;
  protected $_name = 'musicas';
  protected $_primary = 'id';

protected $_referenceMap = array(
        'RelacionamentoTabelas' => array(
        'columns' => 'idmusica',
        'refTableClass' => 'Application_Model_DbTable_Albums',
        'refColumns' => 'id'
    ),
);

public function adicionarMusica($musica, $duracao, $idalbum) {

    //$novoid = new Application_Model_DbTable_Albums();
    //$id = (int) $novoid->setValue('id');
    $data = array(
        'musica' => $musica,
        'duracao' => $duracao,
        'idmusica' => $idalbum
    );
    $this->insert($data);

}

Application_Model_DbTable_Albums

protected $_name = 'albums';

protected $_primary = 'id';

protected $_dependentTables = array('Application_Model_DbTable_Musicas');

call in view to add songs directly from the album id:

ps: Check out the 'id' where I get the id of the album and step right in to be stored with the foreign key, but I think it's wrong.

index.phtml:

<td><a href="<?php echo $this->url(array('controller'=>'musicas', 
            'action'=>'adicionar', 'id' => $album->id));?>">Adicionar música</a></td>

All other methods are working, except this!

    
asked by anonymous 18.07.2014 / 17:31

0 answers