2011-01-09 63 views
1

我有这个模式如下,我已经生成了使用symfony 的类,并使用生成的表单类创建了一对对象。条件:“未定义的偏移”

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

现在我有这样的条件:

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

当我打电话的标准代码,它工作正常,但是这三个通知如下 被显示。

有什么想法?

SF 1.4/1.4推进

通知(!):未定义抵消:2 的/ opt/LAMPP/htdocs中/ prueba/lib中/ 模型/ OM/BaseMotoPeer.php上线379 呼叫堆栈

时间记忆功能位置1 0.0008 328076

{主}()../frontend_dev.php:0 2 0.1974 4333236 sfContext->调度()
../frontend_dev.php:13 3 0.1974 sfFrontWebController->调度()
../ sfContext.class.php:170 4
0.1981 4350256 sfController->向前()../ sfFrontWebController.class .PHP:48 5
0.2134 4641000 sfFilterChain->执行()
../sfController.class.php:238 6
0.2138 4641808 sfRenderingFilter->执行()
../ sfFilterChain.class.php:53 7
0.2138 4641808 sfFilterChain-> execute()../ sfRenderingFilter.class.php:33 8
0.2143 4642588 sfExecutionFilter->执行()
../ 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->执行()../sfExecutionFilter.class.php:92 12 0.2147 4644160 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 5756176个BaseMotoPeer :: populateObjects( )../BaseMotoPeer.php:241个16
0.2493 5756568 BaseMotoPeer :: getPrimaryKeyHashFromRow( )../BaseMotoPeer.php:400

(! )注意:未定义抵消:1 的/ opt/LAMPP/htdocs中/ prueba/lib中/ 模型/ OM/BaseMoto.php上线184呼叫 堆栈

时间记忆功能位置1 0。0008 328076

{主}()../frontend_dev.php:0 2 0.1974 4333236 sfContext->调度()
../frontend_dev.php:13 3 0.1974 sfFrontWebController->调度( )
../ sfContext.class.php:170 4
0.1981 4350256 sfController->向前()../ sfFrontWebController.class.php:48 5
0.2134 4641000 sfFilterChain->执行()
.. /sfController.class.php:238 6
0.2138 464 1808 sfRenderingFilter->执行()
../ sfFilterChain.class.php:53 7
0.2138 4641808 sfFilterChain->执行()../ sfRenderingFilter.class.php:33 8
0.2143 4642588 sfExecutionFilter->执行()
../ 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 4644160 motoActions-> executePrueba()
../sfActions.class.php:60 13
0.2212 5026172 MotoPeer :: prueba()../actions.class.php:14 14 0.2254 5285592 BaseMotoPeer ::的doSelect ()
../MotoPeer.php:26 15 0.2493 5756176个BaseMotoPeer :: populateObjects( )../BaseMotoPeer.php:241 16
0.2578 5953424 BaseMoto->水合物()../BaseMotoPeer.php:408

(! )注意:未定义偏移:2 /选择/ LAMPP/htdocs中/ prueba/LIB/ 模型/ OM/BaseMoto.php上线185呼叫 堆栈

时间记忆功能位置1 0.0008 328076

{主}()../frontend_dev.php:0 2 0.1974 4333236 sfContext->调度()
../frontend_dev.php:13 3 0.1974 sfFrontWebController->调度()
../ sfContext .class.php:170 4
0.1981 4350256 s fController->向前()../ sfFrontWebController.class.php:48 5
0.2134 4641000 sfFilterChain->执行()
../sfController.class.php:238 6
0.2138 4641808 sfRenderingFilter->执行( )
../ sfFilterChain.class.php:53 7
0.2138 4641808 sfFilterChain->执行()../ sfRenderingFilter.class.php:33 8
0.2143 4642588 sfExecutionFilter->执行()
../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->执行()../sfExecutionFilter.class.php:92 12 0.2147 4644160 motoActions-> executePrueba()
../sfActions.class.php:60 13
0.2212 5026172 MotoPeer :: prueba()../actions.class.php:14 14 0.2254 5285592 BaseMotoPeer ::的doSelect()
../MotoPeer.php:26 15 0.2493 5756176 BaseMotoPeer :: populateObjects( )../BaseMotoPeer.php:241 16
0.2578 5953424 BaseMoto->水合物()../BaseMotoPeer.php:408

编辑:第一通知出现,因为我没有写在模型的字段之前的“id:〜”。这里有云导致第二和第三通知书行:

/** 
    * 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 

我认为,第二个和第三个声明是因为在我刚一列(maatricula)的标准显示。但如何做到这一点?

哈维尔

+0

张贴在通知中提到的行将有助于... – greg0ire 2011-01-09 17:01:24

回答

1

如果使用“AddSelectColumn”的方法:

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

你不能滋润对象 - 你没有选择的所有列。因此,不叫:

MotoPeer::doSelect($c); 

而是做到这一点:

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

在这里,您执行SQL语句并获取你有兴趣到变量$ max_matricula单值。