It just so happens that I've just had to do this, and I've found a
(straightforward) way that works perfectly.
Here's a cut-down version with the necessary stuff:
-- /app/models/contact.ctp ---
class Contact extends AppModel {
var $name = "Contact";
var $useTable = false;
function schema() {
return array(
'id' => array('type' => 'integer', 'null' => '',
'default' =>
'1', 'length' => '8', 'key'=>'primary'),
'name' => array('type' => 'string' , 'null' => '',
'default' =>
'', 'length' => '255'),
'email' => array('type' => 'string' , 'null' => '',
'default' =>
'', 'length' => '155'),
'address' => array('type' => 'string' , 'null' => '',
'default' =>
'', 'length' => '255'),
'enquiry' => array('type' => 'string' , 'null' => '',
'default' =>
'', 'length' => '255')
);
}
var $validate = array(
'email' => array(
'rule' => 'email',
'allowEmpty' => false,
'required' => true,
'message' => 'You must specify a valid email address'
)
)
}
--- /app/controllers/contact_us_controller.php ---
class ContactUsController extends AppController {
var $name = "ContactUs";
var $uses = array('Contact');
var $components = array('Email');
function index() {
if (!empty($this->data)) {
$this->Contact->set($this->data);
if ($this->Contact->validates()) {
// Email details omitted
$this->set('title', "Contact form was sent");
}
else {
$this->Session->setFlash('Please correct errors below');
$this->set('title', "Could not sent form");
}
}
}
--- /app/views/contact_us/index.ctp ---
(excerpt)
<?php echo $form->create('Contact', array('url' => '/contact-us/',
'class' => 'contact')); ?>
<div class="row required">
<div class="label">
<?php echo $form->label('email'); ?>
</div>
<div class="field">
<?php echo $form->text('email', array('class' => 'txt', 'size'
=> 26)); ?>
<?php echo $form->error('email'); ?>
</div>
</div>
<!--- other form fields here -->
<?php echo $form->end('Submit'); ?>
On Jan 22, 11:35 am, grigri <[EMAIL PROTECTED]> wrote:
> Have you tried implementing YourModel::schema()?
>
> I think you need to when the database is not available.
>
> On Jan 22, 10:22 am, Matt <[EMAIL PROTECTED]> wrote:
>
> > I've got a working database configuration as the other models use the
> > database.
>
> > This model doesn't use the database because I am just using its
> > validation methods to validate a form.
>
> > On Jan 21, 6:00 pm, duRqoo <[EMAIL PROTECTED]> wrote:
>
> > > You still have to have database.php file in your /app/config. Content
> > > of the file is list of data sources u will use in your app. Default
> > > one must be there, otherwise it will throw you those fatal errors. So
> > > your database.php file should at least look like this (copied from
> > > database.php.default).
>
> > > class DATABASE_CONFIG {
> > > var $default = array(
> > > 'driver' => 'mysql',
> > > 'persistent' => false,
> > > 'host' => 'localhost',
> > > 'port' => '',
> > > 'login' => 'user',
> > > 'password' => 'password',
> > > 'database' => 'database_name',
> > > 'schema' => '',
> > > 'prefix' => '',
> > > 'encoding' => ''
> > > );
>
> > > }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---