Org's join action view:
<?php echo $form->create('Org', array('action' => 'join')); ?>
<?php echo $form->input('User.id', array('type' => 'hidden', 'value' =>
$user_id)); ?>
<?php echo $form->input('Org.id', array('type' => 'hidden', 'value' =>
$org_id)); ?>
<div class="form_wrapper">
<div class="form_field_wrapper">
<div class="form_field_title">
Post:
</div>
<div class="form_field_input">
<?php echo $form->input('OrgsUser.post', array('label' => ''));
?>
</div>
</div>
<div class="form_field_wrapper">
<div class="form_field_title">
Start:
</div>
<div class="form_field_input">
<?php echo $form->input('OrgsUser.start', array('label' => ''));
?>
</div>
</div>
<div class="form_field_wrapper">
<div class="form_field_title">
Finish:
</div>
<div class="form_field_input">
<?php echo $form->input('OrgsUser.finish', array('label' =>
'')); ?>
</div>
</div>
<div class="form_field_wrapper">
<div class="form_field_title">
I'm working now:
</div>
<div class="form_field_input">
<?php echo $form->input('OrgsUser.work_now', array('label' =>
'')); ?>
</div>
</div>
<div class="form_field_wrapper">
<div class="form_field_title">
<?php echo $form->end('Save'); ?>
</div>
</div>
</div>
I don't know how to insert data properly, because I use it:
function join($id = null) {
$this->layout = 'register';
$thisUser = $this->Session->read('User');
$thisOrg = $id;
$this->set('user_id', $thisUser['User']['id']);
$this->set('org_id', $thisOrg['Org']['id']);
if (!empty($this->data)) {
$this->Org->set($this->data);
if ($this->Org->validates()) {
$start =
$this->data['OrgsUser']['start']['year']."-".$this->data['OrgsUser']['start']['month']."-".$this->data['OrgsUser']['start']['day'];
$finish =
$this->data['OrgsUser']['finish']['year']."-".$this->data['OrgsUser']['finish']['month']."-".$this->data['OrgsUser']['finish']['day'];
$q = "
insert into
rabota_orgs_users
(`user_id`, `org_id`, `post`, `start`, `finish`,
`work_now`)
values
( '".$this->data['User']['id']."',
'".$this->data['Org']['id']."',
'".$this->data['OrgsUser']['post']."',
'".$start."',
'".$finish."',
'".$this->data['OrgsUser']['work_now']."')
";
$this->Org->query($q);
$this->redirect('/orgs/view/'.$this->data['Org']['id']);
}
}
}
It works, but I think, this is not a best way of using CakePHP. How to do it
properly?
15 февраля 2010 г. 20:14 пользователь John Andersen <[email protected]
> написал:
> How do you save your data in your controller/model?
> John
>
> On Feb 15, 4:33 pm, Александр Бармин <[email protected]>
> wrote:
> > Nyargh! I'm stupid)))
> >
> > Hm, how I can insert additional data into OrgsUser table, like `post`? In
> > view I create input form like $form->input('OrgsUser.post');, but data
> from
> > this field is not inserted in orgs_users table. What's matter?
> >
> > 15 февраля 2010 г. 19:24 пользователь John Andersen <
> [email protected]
> >
> >
> >
> > > написал:
> > > Got it :) An example using your information would be:
> > > [code
> > > $this->OrgUser->deleteAll( array( 'org_id' => $orgId, 'user_id' =>
> > > $userId ) );
> > > [/code]
> >
> > > Enjoy,
> > > John
> >
> > > On Feb 15, 2:09 pm, Александр Бармин <[email protected]>
> > > wrote:
> > > > rabota_ is prefix for table =)
> >
> > > > Can you take me an example of using DeleteAll?
> >
> > > > 2010/2/15 John Andersen <[email protected]>
> >
> > > > > Use the models deleteAll method! See the CakePHP book at:
> > > > >http://book.cakephp.org/view/516/Deleting-Data#deleteAll-692
> >
> > > > > Note that your CREATE statement states that the HABTM table is
> named
> > > > > "rabota_orgs_users" but your association definition in the Org
> model
> > > > > mentions the table "orgs_users". Please check all your model names
> and
> > > > > table names for inconsistencies!
> >
> > > > > Enjoy,
> > > > > John
> > > [snip]
> >
> > > 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 [email protected]
> > > To unsubscribe from this group, send email to
> > > [email protected]<cake-php%[email protected]>
> <cake-php%[email protected]<cake-php%[email protected]>>For
> more options, visit this group at
> > >http://groups.google.com/group/cake-php?hl=en
> >
> > --
> > С уважением, Александр Бармин.
> > Мой сайт:http://www.barmin-aleksandr.ru/
>
> 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 [email protected]
> To unsubscribe from this group, send email to
> [email protected]<cake-php%[email protected]>For
> more options, visit this group at
> http://groups.google.com/group/cake-php?hl=en
>
--
С уважением, Александр Бармин.
Мой сайт: http://www.barmin-aleksandr.ru/
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 [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