I didn't know about the default function arguments in PHP, know i know
it's name i see it too in the PHP manual but couldn't find it in the
cake docs en tutorial, so for all others with problems:
http://www.php.net/manual/en/functions.arguments.php section 'Default
argument values' and example 3
A thank you, and now I think i understand setting to default null is
necessary to use it as an add function too, so calling the add
function or an empty edit function would be the same, except the
templates and setflash saying saved or updated
On 25 nov, 06:45, Patrick Talmadge <ptalma...@gmail.com> wrote:
> 1. edit($id = null) will set the default value of $id to null if
> nothing is passed into edit. If a value is passed to edit $id = null
> will be ignored.
> 2. $this->Post->id = $id will assign the value of $id to the Post
> model. If nothing is passed into edit() null will be assigned.
> 3. if(empty($this->data)) is checking the current form data. If data
> is empty the form hasn't been submitted. $this->data =
> $this->Post->read(); than pulls the Post data and assigns it to data
> so the form can be populated with the current Post values for editing.
>
>
>
> On Tue, Nov 24, 2009 at 4:58 PM, cakephp9 cakephp9 <cakep...@gmail.com> wrote:
> > I have some basic questions about the blog tutorial
>
> > 1 What does edit($id = null) mean, is $id being reset tot null?
> > 2 What does $this->Post->id = $id; then do, make it null too?
> > 3 Why do we check again if the data is empty, the data validation
> > prevents it from being empty?
>
> > Thanks in advance!
>
> >http://book.cakephp.org/view/340/Editing-Posts
>
> > function edit($id = null) {
> > $this->Post->id = $id;
> > if (empty($this->data)) {
> > $this->data = $this->Post->read();
> > } else {
> > if ($this->Post->save($this->data)) {
> > $this->Session->setFlash('Your post has been updated.');
> > $this->redirect(array('action' => 'index'));
> > }
> > }
> > }
>
> > Check out the new CakePHP Questions sitehttp://cakeqs.organd help others with their CakePHP related questions.
>
> > You received this message because you are subscribed to the Google Groups "CakePHP" group.
> > To post to this group, send email to cake-php@googlegroups.com
> > To unsubscribe from this group, send email to
> > cake-php+unsubscribe@googlegroups.com For more options, visit this group athttp://groups.google.com/group/cake-php?hl=en- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -
Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
No comments:
Post a Comment