Hello there!
So I've started to get the hang of how the models, controllers and
views work together. It was a bit of an uphill to start with but I've
managed to create quite a few good, sound working sections in cakePHP
which makes me think that I at least have some knowledge about how
things should work.
Now, I've been thinking about a specific part of an application I'm
building and it has to do with newsletters and e-mail registrations.
The section of the application's different functions are simple
enough;
* Index (Here you have the option to click subscribe and unsubscribe
links)
* Subscribe (Provide a valid email address, this in turn sends an
email sent to you with a verification code)
* Verify (With the help of your address and verification code, you
verify that you've recieved the subscription email)
* Unsubscribe (Provide an email-address to unsubscribe)
I'm almost done with the entire section but I'm becoming more and more
unsure if I'm attacking this from the right angles. It seems, as I've
gotten further and further into trying to figure out how to solve
different types of things, I'm more and more letting go of cakePHP's
structure, almost coding everything by hand as I would without using
cake.
For example; The registration page. It works perfect, I get an email
sent to me and whatnot but I've "lost" some of cakePHP's powers in the
process.
On the registration page I've got the following in my controller:
if(!empty($this->data)) {
$this->data['Lunch']['code'] = $this->Generic-
>generatePassword(4);
if($this->Lunch->save($this->data)) {
$this->Generic->sendEmail($this->data['Lunch']['email'], $this-
>data['Lunch']['code']);
$this->flash('Data saved!', '/newsletter');
}
}
As you can see I'm using a component called "Generic" (I had a bit of
a dry-out when choosing name, I'm aware) which holds both code
generating functions and email handling. The view only consists of one
field so far; "Enter your email address". It works fine insofar that
if I don't provide an email address, I don't get an email and the
address isn't stored anywhere. If I do provide an email address, but
it's in the wrong format, I get notified of this by cake's built-in
error handler. If I provide a correct email address, everything is
working and I get a flash-message that everything has worked out.
The model is very simple:
class Newsletter extends AppModel {
var $name = 'Newsletter';
var $validate = array(
'email' => VALID_EMAIL
);
}
Not very much to comment on here.
The view:
Subscribe to our newsletter
<form name="lunchForm" method="post" action="register">
Email address: <?php echo $html->input('Newsletter/email',
array('size' => 20)); ?><?php echo $html->tagErrorMsg('Newsletter/
email', 'You have to provide a valid email address!'); ?>
<?php echo $html->submit('Subscribe!'); ?>
</form>
As the model states, it gives me an error when the address is in the
wrong format but do I have to state some other validation method to
make it work with an empty field?
What I've lost here in the process are the following:
* My database table of this consists of a unique field called "email"
apart from the regular "id" primary key field. When I enter an email
address that already exists in the database I get an ugly SQL-parse
error. None of the nicely styled and handled error messages that cake
provides.
* If I don't provide an email address, I get no error whatsoever. The
page reloads as if nothing's happened and I get to provide the address
again. I've completely and entirely lost the error handling.
Now, what I'd like to know is this; Am I going about this the right
way or am I not using cake's potential at all? Are there mutiple ways
of solving this?
Thank you for your time! It's much appreciated!
Regards
DrLaban
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---