That looks good to me! Ended up nice and simple in the end. I love Cake! Don
On May 13, 12:12 am, Alonso <[email protected]> wrote: > function add() { > if (!empty($this->data)) { > //********************You mean this ,right? > ****************************** > $this->data['Post']['user_id']=$this->Auth->user('id'); > // > *************************************************************************** > > $this->Post->create(); > > if ($this->Post->save($this->data)) { > $this->Session->setFlash(__('The post has > been saved', true)); > $this->redirect(array('action' => 'index')); > } else { > $this->Session->setFlash(__('The post could > not be saved. Please, > try again.', true)); > } > } > } > I had no idea this was even possible. Thank you so much > > P.S. I'm really sorry for causing you so much trouble > > On 12 mayo, 18:41, dreamingmind <[email protected]> wrote: > > > > > > > > > To avoid putting the user id on the form in a hidden field, couldn't > > you just wait for the add action to receive the POST data, then get > > the user id from auth->user('id') and add that to the POSTed data > > array before saving? > > > In that way, you would never have to worry about verifying that the id > > value that came back with the form had not been changed. > > > Regards, > > Don > > > On May 12, 3:43 pm, Alonso <[email protected]> wrote: > > > > Yes, that's exactly what I wanted, I needed to "pre-set" the content > > > of the field and to avoid showing a select with all the registered > > > users when adding a new post(views\posts\add.ctp), I opted for > > > creating a private function , _usersUserid() , in the > > > app_controller.php , that returns the user_id of the current logged- > > > in user > > > > *************app_controller.php**************** > > > > function _usersUserid(){ > > > $users_userid=0; > > > if ($this->Auth->user()){ > > > $users_userid=$this->Auth->user('id'); > > > } > > > return $users_userid; > > > } > > > which I then send to the "add" view > > > function beforeFilter() { > > > //some other code > > > $this->set('users_userid',$this->_usersUserid()); > > > } > > > > *************Add View (views\posts\add.ctp) **************** > > > Where in order to know which user registers the new post , I've > > > created a new input hidden field to store the user_id > > > <?php > > > //echo $this->Form->input('user_id'); > > > > echo $this->Form->input('user_id',array('type' => > > > 'hidden', > > > 'value' => $users_userid )); > > > > echo $this->Form->input('title'); > > > echo $this->Form->input('body'); > > > ?> > > > > and with this everything works fine, but I'm not so sure if this is > > > the best solution. what do you think?? > > > > thanks in advance > > > > P.S. Sorry for my English > > > > On 12 mayo, 10:54, dreamingmind <[email protected]> wrote: > > > > > It sounds like you want to pre-set the content of the field? That > > > > would be the 'value' property. > > > > > $form->input->('myfiled', array('value' => 'This will show as the > > > > fields starting content')); > > > > > Regards, > > > > Don > > > > > On May 12, 6:31 am, Alonso <[email protected]> wrote: > > > > > > you're right,there is an array of users ($users), but I'm afraid I > > > > > haven't explained myself well, what I'd like to know is if it's > > > > > possible to display a constant string using input()? because every- > > > > > time I try to do this, the string is displayed, but as a label. > > > > > > P.S. I did try what you told me about placing array('type' => 'text') > > > > > as the > > > > > second argument of the input method, but it only forces the control to > > > > > be a input text > > > > > > On 11 mayo, 20:38, Miles J <[email protected]> wrote: > > > > > > > Theres some magic that happens. If you have an ID field (user_id), > > > > > > it > > > > > > will usually be a select. If you set a variable called $users to the > > > > > > view, that input field will populate with that data. > > > > > > > You can overwrite that by just placing array('type' => 'text') as > > > > > > the > > > > > > second argument of the input method. > > > > > > > On May 11, 10:54 am, Alonso <[email protected]> wrote: > > > > > > > > Hi, folks. > > > > > > > I'm starting with CakePHP and after reviewing this tutorial > > > > > > > (http://book.cakephp.org/view/1543/Simple-Acl-controlled-Application > > > > > > > ) and also after having used the "cake bake" command to > > > > > > > generate my > > > > > > > models, > > > > > > > controllers and views , everything is fine, but when I visit the > > > > > > > Post's add view (views \ posts > > > > > > > \ add.php), I find that instead of showing a input text for the > > > > > > > username, it shows a select with all the usernames. > > > > > > > > this is the line in the Post's add view that show the select. > > > > > > > > echo $this->Form->input('user_id'); > > > > > > > > Although I know how to display only the username of the currently > > > > > > > logged-in user, I don't know how to control the content to show > > > > > > > in > > > > > > > $this->Form->input() because if I use a variable that is not > > > > > > > part of > > > > > > > the "Post" model , it's shown , but as the label for the input. > > > > > > > > Have you any idea how to solve this?? -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php
