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

  • Home
  • SEARCH
  • 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 8807785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:27:16+00:00 2026-06-14T02:27:16+00:00

i am new to cake and using version 2. i have models hgcylinder.php class

  • 0

i am new to cake and using version 2.

i have models

hgcylinder.php

class HgCylinder extends AppModel  {
    //put your code here
    var $name= "HgCylinder";

    var $belongsTo = array('HgKeyGase');
}

hgkeygase.php
class HgKeyGase extends AppModel  {
    //put your code here
    var $name= "HgKeyGase";


    public $belongsTo = array(
        'HgKeyColor' => array(
            'className' => 'HgKeyColor',
            'foreignKey' => 'hg_key_color_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        )
        );

}

Controller HgCylindersController.php

<?php

class HgCylindersController extends AppController
{
    var $name = "HgCylinders";
    // var $scaffold;
    function index()
    {
        $this->set('hey',$this->HgCylinder->find('all'));
    }


    public function edit($id = null) {
        $this->HgCylinder->id = $id;
        if ($this->request->is('post')) {
        var_dump($this->request->data);
        exit;
            if ($this->HgCylinder->save($this->request->data)) {
                $this->Session->setFlash(__('Cylinder has been updated successfull'));
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The cylinder could not be saved. Please, try again.'));
            }
        } else {
            $this->request->data = $this->HgCylinder->read(null, $id);
        }
        $hg_key_gase_id = $this->HgCylinder->HgKeyGase->find('list');

        $this->set(compact('hg_key_gase_id'));
    }

} 

?>

View : edit.ctp
<?php 

echo $this->form->create('HgCylinder',array('action'=>'edit'));
echo $this->form->input('hg_key_gase_id',);
echo $this->form->input("capacityM3");
echo $this->form->input("weightEmpty");
echo $this->form->input("weightFilled");
echo $this->form->input("isFilled");
echo $this->form->end('Add');
?>

my problem is hg_key_gase_id is become select list with no options. if i changed the name to “hgKeyGas” in view and controller it shows the options from the hg_key_gases table. but on saving does not saving the value of hg_key_gase_id field in hg_cylinders table instead it stores null in this field.

second i want to know that it is necessary to have variable name passing to view from controller exactly same for as field in table.

  • 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-14T02:27:17+00:00Added an answer on June 14, 2026 at 2:27 am

    try to stick to conventions.

    so its

    $hgKeyGases = $this->HgCylinder->HgKeyGase->find('list');
    
    $this->set(compact('hgKeyGases'));
    

    the pluralized form will be able to populate your select box (as documented in the cook book)

    also use $this->Form->input() (note the capital F). $name is not necessary.
    dont use read(), use find(first) instead. dont set the action (the form will post to itself by default).

    and most importantly. ALWAYS respect the casing of files in your filesystem. especially if you plan on deploying on NIX systems (which are case sensitive).
    so it would be HgCylinder.php and HgKeyGase.php as Model class files.

    last tip: use baking (cake bake via shell console) to bake your crud files. this way you learn how its done the right way. it would have also answered your question itself by the way.

    the documentation can be found here: http://book.cakephp.org/2.0/en/index.html
    maybe you found an old outdated version, the 2.x one is the one you should have used.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm pretty new to Cake and am using Cake 2.0 and I have baked
I am using cake php now. I have two file example1.ctp and example2.ctp. I
New to PHP and MySQL, have heard amazing things about this website from Leo
New programmer here, I am trying to understand and break down this code below
New developer here,Im using the Custom Image Picker by ray wenderlich. But what I
Here's the code. public class testClient { public static void main(String[] args) { testClient
EDIT: Yields that there is already new PHP framework written as extension. http://code.google.com/p/yafphp ,
im struggling with my cake code(very new to cakephp) and was after some help.
Totally new to Cake. I have this table named Content and another one named
I'm using this code in my action to register a new user: public function

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.