Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: 1 [2]
Print
Author Topic: [SOLVED] :) HELP-ME URGENTLY!!!! VO DATA  (Read 19736 times)
Vander
Full Member
***
Posts: 32


View Profile Email
« Reply #15 on: June 22, 2008, 09:45:30 »

Yes it have much sense! ive thinked this together with your last post...

if i create a new usuariovo on php, i can retrieve it
but
do you know how can i automatize using for... to populate automatically?

very thankx cliff

:
function recolheDados ( $id, $tabela ) {
      $sql = "SELECT * FROM $tabela WHERE id_" . $tabela . " = $id";
      $teste = new UsuarioVO( );
      $teste->nome="van";
      return _query( $sql );
      }

this code is wrong.. because its returning the query... as object
but im posting to show you..
because if i return $teste.. it cames as UsuarioVO :)
but do you know how to create a routine that parses query and puts automagically, a iterated loop.. that puts all variables inside the object to return?

very thanks
Logged
Vander
Full Member
***
Posts: 32


View Profile Email
« Reply #16 on: June 22, 2008, 11:32:03 »

hey cliff
got it

         function recolheDados ( $id, $tabela ) {
            $sql = "SELECT * FROM $tabela WHERE id_" . $tabela . " = $id";
         $objeto = new UsuarioVO();
         $query = mysql_fetch_array(_query($sql));
         foreach ($query as $key => $value) {
            $objeto->$key = $value;
         }            
            return $objeto;
         }
        

just one last problem
since ive created a dynamic function
how can i tell it to instantiate the correct type of object, based on table that ive passed no argument?

$objeto = new UsuarioVO();    <- how to dynamically change UsuarioVO for another VO depending of the table passed? theres no way? i will must do a switch case?

thanks for all
Logged
Vander
Full Member
***
Posts: 32


View Profile Email
« Reply #17 on: June 22, 2008, 11:36:00 »

hmm another strange behaviour

the result are doubled

:
(Object)#0
  0 = "1"
  1 = "vander"
  10 = "0"
  11 = ""
  12 = ""
  13 = ""
  14 = ""
  15 = "0"
  16 = "0"
  17 = "0"
  18 = "0"
  19 = "0"
  2 = "teste"
  20 = ""
  21 = "0"
  22 = "2008-06-06 13:57:55"
  23 = "0"
  24 = "0000-00-00 00:00:00"
  25 = "0"
  3 = "0"
  4 = "0"
  5 = "Vander Ferreira Hiar"
  6 = "0"
  7 = "333111222"
  8 = "0"
  9 = ""
  arquivo = "0"
  bairro = ""
  celd = "0"
  celn = "0"
  cep = "0"
  cidade = ""
  comp = ""
  cpf = "333111222"
  data_ins = "2008-06-06 13:57:55"
  data_upd = "0000-00-00 00:00:00"
  email = (null)
  end = ""
  end_num = "0"
  equipe = "0"
  estado = ""
  id_ins = "0"
  id_upd = "0"
  id_usuario = "1"
  id_usuario2 = (null)
  level = "0"
  nome = "Vander Ferreira Hiar"
  obs = ""
  rg = "0"
  senha = "teste"
  teld = "0"
  teln = "0"
  tipo = "0"
  usuario = "vander"

i cant figure out why .. since im returning only the $object why its filling with field name and index together?

i guess that im lacking of php knowledge a bit.

thanks for help.. and i have sure that it will help many ppl with the same problem!
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #18 on: June 22, 2008, 11:39:52 »

Yep, that's where my knowledge starts to run a little thin as well. I'm not a PHP guy. I'll be picking it up soon, but for now, I'm at a loss to tell you what's going wrong there.

Again, you might want to look into WebORB. I believe it automates a lot of this for you.

-=Cliff>
Logged
Vander
Full Member
***
Posts: 32


View Profile Email
« Reply #19 on: June 22, 2008, 12:12:54 »

SOLVED!

instead of using mysql_fetch_array, i must use mysql_fetch_assoc

and i can use dynamic name :)

so the code is

:
        // function for dynamic data read, with class mapping :)
    function recolheDados ( $id, $tabela, $voname ) {
      $sql = "SELECT * FROM $tabela WHERE id_" . $tabela . " = $id";
$objeto = new $voname();
$query = mysql_fetch_assoc(_query($sql));
foreach ($query as $key => $value) {
$objeto->$key = $value;
   
      return $objeto;
      }
Logged
Pages: 1 [2]
Print