Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7914283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:04:06+00:00 2026-06-03T14:04:06+00:00

I’ve been trying to figure this problem out all morning. Tried some things from

  • 0

I’ve been trying to figure this problem out all morning. Tried some things from other questions, but it either didn’t really apply to my situation or didn’t work. I have two tables:

users = (id,name,username,password,roles,last_edit,language)
french_translations = (id, french_clinical_recommendations, french_tradenames, include_drug, french_category, drug_id, user_id)

User hasMany french_translations and french_translations belongsTo User.

When a user adds or edits a french_translation I want it to save the user id in the french_translations table, the field user_id, for that record, and then put the generic name for a drug in the last_edit field in the users table. Right now it creates a new record in each table. In the users table, everything is blank except for the id and last_edit field(Which puts the correct drug name in the field). And the french_translations table has a record with blanks, with the user_id being the same as the blank one created in the users table.

Controller:

    function add($id = null) {
    $userid = $session->read('Auth.User.id');
    $drug = $this->FrenchTranslation->Drug->read(
      array(
          'Drug.id','Drug.generic','Drug.ahl','Drug.aap','Drug.rid','Drug.oral','Drug.mw','Drug.clinical_recommendations',
          'Drug.category','Drug.lrc'
      ),
      $id
    );
    $this->set('user',$userid);
    $this->set('drug',$drug);

    if (!empty($this->data)) {
      $french_translation['FrenchTranslation']['id'] = $this->Session->read('id');
            $this->FrenchTranslation->create();
            if ($this->FrenchTranslation->save($this->data)) {
                $this->Session->setFlash(__('The french translation has been saved', true));
                $this->redirect(array('controller'=>'drugs','action' => 'index'));
            } else {
                $this->Session->setFlash(__('The french translation could not be saved. Please, try again.', true));
            }
        }
        $drugs = $this->FrenchTranslation->Drug->find('list');
        $this->set(compact('drugs'));
    }

    function edit($id = null) {
    //$this->FrenchTranslation->id = $id;
    $userid = $this->Auth->user('id');
    $username = $this->Auth->user('name');
  //$this->FrenchTranslation->user_id = $id;
    $drug = $this->FrenchTranslation->Drug->read(
      array(
          'Drug.id','Drug.generic','Drug.ahl','Drug.aap','Drug.rid','Drug.oral','Drug.mw','Drug.clinical_recommendations',
          'Drug.category','Drug.lrc'
      ),
      $id
    );

    $this->set('drug',$drug);
    $this->set('user',$userid);
    $this->set('username',$username);

        if (!$id && empty($this->data)) {
            $this->Session->setFlash(__('Invalid french translation', true));
            $this->redirect(array('action' => 'index'));
        }
        if (!empty($this->data)) {
            if ($this->FrenchTranslation->saveAll($this->data)) {
                $this->Session->setFlash(__('The french translation has been saved', true));
                $this->redirect(array('controller'=>'drugs','action' => 'index'));
            } else {
                $this->Session->setFlash(__('The french translation could not be saved. Please, try again.', true));
            }
        }
        if (empty($this->data)) {
            $this->data = $this->FrenchTranslation->read(null, $id);
        }
        $drugs = $this->FrenchTranslation->Drug->find('list');
        $this->set(compact('drugs'));
    }

    function delete($id = null) {
        if (!$id) {
            $this->Session->setFlash(__('Invalid id for french translation', true));
            $this->redirect(array('action'=>'index'));
        }
        if ($this->FrenchTranslation->delete($id)) {
            $this->Session->setFlash(__('French translation deleted', true));
            $this->redirect(array('action'=>'index'));
        }
        $this->Session->setFlash(__('French translation was not deleted', true));
        $this->redirect(array('action' => 'index'));
    }

Edit View:

    <?php echo $this->Form->input('User.last_edit',array('type'=>'hidden','value'=>$drug['Drug']['generic'])); ?>    
    <?php echo $this->Form->input('user_id', array('type'=>'hidden','value'=>$user)); ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T14:04:10+00:00Added an answer on June 3, 2026 at 2:04 pm

    I figured it out, however, I feel like there’s a better and more secure, way of doing it. I am using the security component, and a person has to login to see any of the site, so it’s probably safe enough.

    I simply added a user.id input for the user id, at that point it could find the appropriate user to store the last_edit into. In the controller I have a variable called $userid which gets the current user id using $userid = $this->Auth->user('id'); and is passed to the view using $ths->set('user',$userid); I used that same user id value in the input for the drugs user_id field.

    View:

    <?php echo $this->Form->input('User.id',array('type'=>'hidden','value'=>$user));//The user ID last edit will be stored in ?>
    <?php echo $this->Form->input('User.last_edit',array('type'=>'hidden','value'=>$drug['Drug']['generic']));//The drug edited last by the specified user ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I am currently running into a problem where an element is coming back from
I have some data like this: 1 2 3 4 5 9 2 6
I have a jquery bug and I've been looking for hours now, I can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.