4

I have a form that a user selects a document in. This document is then saved to the webroot folder by the controller.

However, before it even shows the form, it gives me an error:

Missing Database Table
Error: Table office_layouts for model OfficeLayout was not found in datasource default.

Which is correct, there is no database table for office_layouts. But it's not needed. That's why there is no table. The form is just uploaded to the server.

I have read through creating forms, and have tried the following:

// file: View/OfficeLayout/upload.ctp
echo $this->Form->create( null ,array('type' => 'file')); ?>
<fieldset>
    <legend><?php echo __('&emsp;Add Layout for ' . $branch); ?></legend>
    <?php
        echo $this->Form->input('layout',array('type'=>'file'));
    ?>
</fieldset>
<?php echo $this->Form->end(__('Submit')); ?>

As well as chaning the null to the controller name (in this case OfficeLayout). I have also removed all parameters (thus creating it like so: $this->Form->create())

In my controller I have the following:

public function upload($branch = null) {
    $this->set('branch',$branch);
    if(isset($this->request->data['OfficeLayout'])) {
        $file = $this->request->data['OfficeLayout']['layout'];
        if($file['error'] === UPLOAD_ERR_OK && move_uploaded_file($file['tmp_name'],APP . 'docs' . DS . 'layouts' . DS . $branch . '.pdf')) {
            $this->Session->setFlash('New layout successfully uploaded.','default',array('class'=>'notification'));
            $this->redirect(array('action'=>$branch));
        } else {
            $this->Session->setFlash('Error uploading layout. Please contact web admin.','default',array('class'=>'error'));
        }
    }
}

This action get's called with: domain/office_layouts/upload/branch.

Whenever I remove the $this->Form->create() line, it shows the upload view, but then obviously doesn't submit.

So my question in this case is, how can I create a form, without it looking for a table in the database?

2 Answers 2

12

Instead of null, use false:

echo $this->Form->create( false, array('type' => 'file')); ?>
Sign up to request clarification or add additional context in comments.

Comments

0

Fixed it by creating a Model file and just putting this in there:

class OfficeLayout extends AppModel {
    var $useTable = false;
}

1 Comment

There's no need to create an empty model. Just use false when creating the form. More simple :) I added an answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.