Monday 15 April 2013

php - Converting an array into a usable string - cakePHP -


I am working on a simple cake php form. I have a variable $ user_name that is populated from my SQL tables.

I have confirmed

  echo & lt; Pre & gt; '; Print_r ($ user_name); Echo & lt; / Pre & gt; ';   

that the $ user_name is populated correctly. I am trying to use the variable that I have prepared to fill the following form fields automatically

  copy $ this-> Form- & gt; Input ($ modelNameField '.name_of_customer', array ('Read Only' = & gt; 'Readable', 'Labels' = & gt; 'Customer Name', 'Type' = & gt; 'Text' 'Value' = & gt; $ user_name));   

However, there is no suggestion that the area remains empty?

Announcement for $ user_name

  app :: import ('model', 'customer information'); $ CustomerInfos = new customer INFO (); $ User_name = array (); $ User_name = $ customerInfos- & gt; Get_name ($ id);   

-

get_name method

  public function get_name ($ id) {return $ this- & gt; First ', array (' field '= & gt; array (' usr_name '),' conditions' = & gt; array ("customerInfo.id" => $ id)); }   

-

print out from print_a ($ user_name); <$> For the $ Id = 1

  array ([CustomerInfo] = & gt; Array ([usr_name] => Ted Jones))    

This is a very basic question.

The value of the form helper needs to be a string string, not input is something that has to do something like an array.

Your structure has this structure

  $ user_name = array ('Customerinfo' => Array ('usr_name' = & gt; 'Ted Jones')) ;   

The string value you want is in the $ user_name ['CustomerInfo'] ['usr_name'] . There is no way to know that the string that you wanted to keep in the form of that form was in that part of the array.

Do not know why you have to first specify array_pop as an indicator in PHP is easy enough to access values ​​within an array, so try the simplest way first and Go to the array _ php functions if this is somewhat more complicated.

For future reference, if you have an array or a variable and you want to use a value inside it, then debug or print_ar how to access it. And if it is an option of some type of data, then there can be an option, this is a very good reference.

No comments:

Post a Comment