我收到错误的非法字符串偏移量..尝试在Stackoverflow上搜索,但它们没有帮助我.. 请帮助
函数Fetch(){return $ this-> find('list',array('fields'=> array('Employee.id','Employee.firstname','Employee.lastname','Employee.salary'))) ); }
公共功能index(){$ this-> set('employees',$ this-> Employee-> Fetch());
}
<?php
$id = 0;
foreach($employees as $e):?>
<? $id++ ?>
<tr>
<td><?php echo $e{'Employee'}{'id'} ?></td>
<td><?php echo $e['Employee']['firstname'], $e['Employee']['lastname'] ?></td>
<td>2014-04-24</td>
<td>2014-04-29</td>
<td style="text-align:center"><?php echo $e['Employee']['salary'] ?></td>'
</tr>
<?php endforeach; ?>
Warning (2): Illegal string offset 'Employee' [APP\View\Employees\index.ctp, line 19]
Warning (2): Illegal string offset 'id' [APP\View\Employees\index.ctp, line 19]
I
Warning (2): Illegal string offset 'Employee' [APP\View\Employees\index.ctp, line 20]
Warning (2): Illegal string offset 'firstname' [APP\View\Employees\index.ctp, line 20]
I
Warning (2): Illegal string offset 'Employee' [APP\View\Employees\index.ctp, line 20]
Warning (2): Illegal string offset 'lastname' [APP\View\Employees\index.ctp, line 20]
Warning (2): Illegal string offset 'Employee' [APP\View\Employees\index.ctp, line 23]
Warning (2): Illegal string offset 'salary' [APP\View\Employees\index.ctp, line 23]
使用find('all')
。find('list')
仅需要检索两个字段时更适合
function Fetch() {
return $this->find('all', array(
'fields' => array('Employee.id', 'Employee.firstname','Employee.lastname','Employee.salary') )
);
}
然后使用$e
like$e['Employee']['id']
代替$e{'Employee'}{'id'}
。
如果仍然出现错误,请debug($e)
在视图中查看其格式是否正确
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句