Thanks, I think, creation of OrgsUsers model is a best solution. =)
15 февраля 2010 г. 21:42 пользователь John Andersen <[email protected]
> написал:
> You have some issues here with your solution:
> 1) You are using hidden fields for the User.id and the Org.id fields.
> 2) You are using query instead of relying on CakePHP methods and
> association/relationship handling.
>
> For issue 1):
> In your join method (OrgsController), you already know the User.id and
> the Org.id, thus should not have a need to pass it to the HTML and
> back again. Store the Org.id in the session when you first time enters
> the join method with an Org.id ($id).
> Then when the user saves the form, add the User.id and the Org.id to
> the data as:
> [code]
> $this->data['OrgsUser']['user_id'] = $this->Auth->user('id');
> $this->data['OrgsUser']['org_id'] = $this->Session->read('your name
> for the org.id');
> [/code]
>
> For issue 2):
> Perform your save using the OrgsUser model as:
> [code]
> if ( $this->OrgsUser->save($this->data) ) {
> // Do your thing when successfully saved! Redirect etc.
> // Delete the org.id from the session!
> }
> ...
> [/code]
>
> If you have not defined your OrgsUser model, do it and add the
> validations for the data fields, post, start, finish, etc.
> Hopefully this will give you a helping hand to get it running :)
> Enjoy,
> John
>
>
> On Feb 15, 5:55 pm, Александр Бармин <[email protected]>
> wrote:
> > 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.organdhelp
> > > 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]>
> >
> > > <cake-php%[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 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