2011-01-09 13 views
1

Ich habe dieses Schema unten, ich habe die Klassen mit Symfony generiert und erstellt ein Paar von Objekten mit der Form-Klasse generiert.Kriterien: "undefined Offset"

moto: 
    marca: { type: varchar(255), required: true } 
    matricula: { type: integer, required: true } 

Jetzt habe ich diese Kriterien:

$c = new Criteria(); 
    $c->addSelectColumn('MAX('.MotoPeer::MATRICULA.')'); 
    $max_matricula = MotoPeer::doSelect($c); 
    var_dump($max_matricula); 
    return $max_matricula; 

wenn ich rufe die Kriterien Code Es funktioniert ok, aber diese drei Hinweise unten gezeigt werden.

Irgendeine Idee?

sf 1.4/treiben 1,4

Hinweis (!): Offset Nicht definiert: 2 in /opt/lampp/htdocs/prueba/lib/ Modell/om/BaseMotoPeer.php on line 379 Anruf Stack

Zeit Speicher Funktion Position 1 0,0008 328076

{main}() ../frontend_dev.php:0 2 0,1974 4.333.236 sfContext-> dispatch()
../frontend_dev.php:13 3 0,1974 4.333.264 sfFrontWebController-> Dispatch()
../ sfContext.class.php: 170 4
0,1981 4350256 sfController-> forward() ../ sfFrontWebController.class .php: 48 5
0,2134 4641000 sfFilterChain-> execute()
../sfController.class.php: 238 6
0,2138 4641808 sfRenderingFilter-> execute()
../ sfFilterChain.class.php: 53 7
0.2138 4641808 sfFilterChain-> execute() ../ sfRenderingFilter.class.php: 33 8
0,2143 4642588 sfExecutionFilter-> execute()
../ sfFilterChain.class.php: 53 9
0,2144 4643308 sfExecutionFilter-> handleAction()
../ sfExecutionFilter.class.php: 42 10 0,2144 4.643.308 sfExecutionFilter -> ExecuteAction() ../ sfExecutionFilter.class.php: 78 11 0,2144 4.643.336 sfActions-> execute() ../sfExecutionFilter.class.php: 92 12 0,2147 4.644.160 motoActions-> executePrueba()
.. /sfActions.class.php: 60 13
0.2212 5026172 MotoPeer :: prueba() ../actions.class.php:14 14 0.2254 528559 2 BaseMotoPeer :: doSelect()
../MotoPeer.php:26 15 0,2493 5.756.176 BaseMotoPeer :: populateObjects ( ) ../BaseMotoPeer.php: 241 16
0,2493 5756568 BaseMotoPeer :: getPrimaryKeyHashFromRow ( ) ../BaseMotoPeer.php: 400

(!) Hinweis: Undefined offset: 1 in /opt/lampp/htdocs/prueba/lib/ Modell/om/BaseMoto.php on line 184 Anruf Stapel

Zeit Speicher Funktion Position 1 0.0008 328076

{main}() ../frontend_dev.php:0 2 0,1974 4.333.236 sfContext-> Dispatch()
../frontend_dev.php:13 3 0,1974 4.333.264 sfFrontWebController-> dispatch ()
../ sfContext.class.php: 170 4
0,1981 4350256 sfController-> forward() ../ sfFrontWebController.class.php: 48 5
0,2134 4641000 sfFilterChain-> execute()
.. /sfController.class.php: 238 6
0.2138 464 1808 sfRenderingFilter-> execute()
../ sfFilterChain.class.php: 53 7
0,2138 4641808 sfFilterChain-> execute() ../ sfRenderingFilter.class.php: 33 8
0,2143 4642588 sfExecutionFilter-> execute()
../ sfFilterChain.class.php: 53 9
0,2144 4643308 sfExecutionFilter-> handleAction()
../ sfExecutionFilter.class.php: 42 10 0,2144 4643308 sfExecutionFilter-> ExecuteAction() ../sfExecutionFilter.class.php: 78 11 0.2144 4643336 sfActions-> execute() ../sfExecutionFilter.class.php: 92 12 0,2147 4.644.160 motoActions-> executePrueba()
../sfActions.class.php: 60 13
0,2212 5026172 MotoPeer :: prueba() ../actions.class.php:14 14 0,2254 5.285.592 BaseMotoPeer :: doSelect()
../MotoPeer.php:26 15 0,2493 5.756.176 BaseMotoPeer :: populateObjects ( ) ../BaseMotoPeer.php: 241 16
0,2578 5953424 BaseMoto-> Hydrat() ../BaseMotoPeer.php:408

(! Hinweis): Undefined offset: 2 in /opt/lampp/htdocs/prueba/lib/ Modell/om/BaseMoto.php on line 185 Anruf Stapel

Zeit Speicher Funktion Position 1 0,0008 328076

{ Haupt}() ../frontend_dev.php:0 2 0,1974 4.333.236 sfContext-> Dispatch()
../frontend_dev.php:13 3 0,1974 4.333.264 sfFrontWebController-> Dispatch()
../ sfContext .class.php: 170 4
0.1981 4350256 s fController-> forward() ../ sfFrontWebController.class.php: 48 5
0,2134 4641000 sfFilterChain-> execute()
../sfController.class.php: 238 6
0,2138 4641808 sfRenderingFilter-> execute ()
../ sfFilterChain.class.php: 53 7
0,2138 4641808 sfFilterChain-> execute() ../ sfRenderingFilter.class.php: 33 8
0,2143 4642588 sfExecutionFilter-> execute()
../sfFilterChain.class.php: 53 9
0.2144 4643308 sfExecutionFilter-> handleAction()
../ sfExecutionFilter.class.php: 42 10 0.2144 4643308 sfExecutionFilter-> executeAction() ../ SfExecutionFilter.class.php: 78 11 0,2144 4.643.336 sfActions-> execute() ../sfExecutionFilter.class.php: 92 12 0,2147 4.644.160 motoActions-> executePrueba()
../sfActions.class.php: 60 13
0,2212 5026172 MotoPeer :: prueba() ../actions.class.php:14 14 0,2254 5.285.592 BaseMotoPeer :: doSelect()
../MotoPeer.php:26 15 0,2493 5.756.176 BaseMotoPeer :: populateObjects ( ) ../BaseMotoPeer.php: 241 16
0,2578 5953424 BaseMoto-> Hydrat() ../BaseMotoPeer.php:408

EDIT: die erste Nachricht erscheint, weil ich "ID: ~" vor den Feldern des Modells nicht geschrieben habe. Hier geht es um die Linien, die die zweiten und die dritten Hinweise verursachen:

/** 
    * Hydrates (populates) the object variables with values from the database resultset. 
    * 
    * An offset (0-based "start column") is specified so that objects can be hydrated 
    * with a subset of the columns in the resultset rows. This is needed, for example, 
    * for results of JOIN queries where the resultset row includes columns from two or 
    * more tables. 
    * 
    * @param  array $row The row returned by PDOStatement->fetch(PDO::FETCH_NUM) 
    * @param  int $startcol 0-based offset column which indicates which restultset column to start with. 
    * @param  boolean $rehydrate Whether this object is being re-hydrated from the database. 
    * @return  int next starting column 
    * @throws  PropelException - Any caught Exception will be rewrapped as a PropelException. 
    */ 
    public function hydrate($row, $startcol = 0, $rehydrate = false) 
    { 
     try { 

var_dump($row); 

    $this->id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null; 
    $this->marca = ($row[$startcol + 1] !== null) ? (string) $row[$startcol + 1] : null;//184 
    $this->matricula = ($row[$startcol + 2] !== null) ? (int) $row[$startcol + 2] : null;//185 

Ich denke, die zweite und die dritten Hinweise werden gezeigt, da in den Kriterien Ich bin nur eine Spalte bekommen (maatricula). Aber wie geht es so?

Javier

+0

das Posten der Zeilen in den Mitteilungen genannt würde helfen ... – greg0ire

+0

Hallo, danke, ich habe weitere Informationen veröffentlicht. – ziiweb

Antwort

1

Wenn Sie die "AddSelectColumn" Methode verwenden:

$c->addSelectColumn('MAX('.MotoPeer::MATRICULA.')'); 

Sie können das Objekt nicht Hydrat - Sie sind nicht alle Spalten auswählen. Daher rufen Sie nicht:

MotoPeer::doSelect($c); 

Statt dies tun:

$c->addSelectColumn('MAX('.MotoPeer::MATRICULA.')'); 
$stmt = MotoPeer::doSelectStmt($c); 
$max_matricula = $stmt->fetchColumn(0); 

Sie hier die SQL-Anweisung auszuführen und die einzelnen Wert holen, die Sie in in die Variable $ max_matricula interessiert sind.