CakePHP非法字符串偏移量

印子

我收到错误的非法字符串偏移量..尝试在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]
山茱b

使用find('all')find('list')仅需要检索两个字段时更适合

function Fetch() { 
    return $this->find('all', array(
        'fields' => array('Employee.id', 'Employee.firstname','Employee.lastname','Employee.salary') )
    ); 
}

然后使用$elike$e['Employee']['id']代替$e{'Employee'}{'id'}

如果仍然出现错误,请debug($e)在视图中查看其格式是否正确

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Laravel-非法字符串偏移量

警告:字符串偏移量非法

非法的字符串偏移量警告PHP

PHP中的非法字符串偏移量错误

非法字符串偏移量'名称'laravel PHP

警告:非法字符串偏移量“ Opencart 2.1”

警告:“姓氏”的字符串偏移量非法

PHP-数组-非法的字符串偏移量

Codeigniter中的字符串偏移量非法

非法的字符串偏移量'formid'

非法字符串偏移量未定义偏移量:2

将CakePHP部署到PHP 5.4.16会在CakePHP的Core中提供非法的字符串偏移量

带有 float 和 int 字符串的非法字符串偏移量

Twitter API 1.1非法字符串偏移量“状态”

警告:使用foreach时字符串偏移量非法

我所有表行上的PHP“警告:字符串偏移量非法”

非法的字符串偏移量“属性”,如何传递json编码的值

php echo中的非法字符串偏移量“结果”

echo会话数组值-警告非法的字符串偏移量

如何解决这些非法的字符串偏移量警告?

警告:字符串偏移量非法(在数组上)

Laravel在尝试循环JSON API响应时给出了非法的字符串偏移量

PHP错误:警告:字符串偏移量非法“额定值”

(非法字符串偏移量)用于将数据导入数据库

非法的字符串偏移量代码点火器

警告:输入中的字符串偏移量'id'为非法

ErrorException非法的字符串偏移量'service_1'(查看:form.blade.php)

严重性:警告消息:非法字符串偏移量'id'我的项目

我的foreach返回警告:字符串偏移量'productname'非法