Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Using cakephp-2.6.3 on a Windows system.

I just need to edit the row data in the MySQL database table which I listed in the ABCData/index.php file.

Controller

    public function index() {
        $this->set('abcdata', $this->ABCData->find('all'));
    }

    public function edit($custom_id = null) {
        if (!$custom_id) {
            throw new NotFoundException(__('Invalid entry'));
        }

        $post = $this->ABCData->findById($custom_id);
        if (!$abcdata) {
            throw new NotFoundException(__('Invalid entry'));
        }

        if ($this->request->is(array('post', 'put'))) {
            $this->ABCData->custom_id = $custom_id;
            if ($this->ABCData->save($this->request->data)) {
                $this->Session->setFlash(__('Your ABCData has been updated.'));
                return $this->redirect(array('action' => 'index'));
            }
            $this->Session->setFlash(__('Unable to update your ABCData.'));
        }

        if (!$this->request->data) {
            $this->request->data = $abcdata;
        }
    }
}

Model

class ABCData extends AppModel {
    public $primaryKey = 'custom_id';
}

index.ctp

    <h3>ABCData list</h3>
<table>
    <tr>
        <th></th>
        <th>field_1</th>
        <th>field_2</th>
        <th>field_3</th>
        <th>...</th>
        <th>...</th>
        ...
    </tr>

    <?php foreach ($abcdata as $abc): ?>
    <tr>
        <td><?php echo $this->Html->link('Edit', array('action' => 'edit', $abc['ABCData']['custom_id']));?></td>
        <td><?php echo $abc['ABCData']['field_1']; ?></td>
        <td><?php echo $abc['ABCData']['field_2']; ?></td>
        <td><?php echo $abc['ABCData']['field_3']; ?></td>
        <td>...</td>
        <td>...</td>
        ...
    </tr>
    <?php endforeach; ?>
    <?php unset($abcdata); ?>
</table>

edit.ctp

<h1>Edit ABCata</h1>
<?php
    echo $this->Form->create('ABCata');
    echo $this->Form->input('title');
    echo $this->Form->input('body', array('rows' => '16'));
    echo $this->Form->input('custom_id', array('type' => 'hidden'));
    echo $this->Form->end('Save ABCata');
?>

All I have is a table with a foreign key field.

Here custom_id is a unique field only.

I get this error:

Database Error

Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'ABCData.id' in 'where clause' ... ...

Please help.

share|improve this question
    
It's because you are using findById. Write out the find with the appropriate condition clause –  AgRizzo 24 mins ago

1 Answer 1

As said in the comments, you can't search by id if there is no id in your model. You chould do

$post = $this->ABCData->findByCustomId($custom_id);

According to Cake conventions, or you can specify conditions like

$post = $this->ABCData->find('first', array('conditions' =>
                                           array('ABCData.custom_id' => $custom_id)));
share

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.