Error message
Error: Cannot use string offset as an array
File: C:\wamp\www\itsm\app\Model\TaskAttribute.php
Line: 48
lines of error
47 foreach($items as $row){
48 $categoryId = $row['Category']['id'];
49 $item_id = $row['Item']['id'];
50 $attr_id = $row['Attribute']['id'];
My Method
public function getTree($branch_id = NULL){
$tree = array();
$items = $this->find('list',array(
'fields' => array('ItemAttribute.item_id','ItemAttribute.item_id'),
'joins' =>array(
array(
'table' => 'item_attributes',
'alias' => 'ItemAttribute',
'type' => 'INNER',
'conditions' => 'TaskAttribute.item_attribute_id = ItemAttribute.id',
),
),
'recursive'=>-1
)
);
if(isset($items)){
$assets = $this->Checklist->ChecklistAttribute->AssetAttribute->Asset->getList($branch_id ,array_keys($items));
//pr($assets);die();
}
foreach($items as $row){
$categoryId = $row['Category']['id'];
$item_id = $row['Item']['id'];
$attr_id = $row['Attribute']['id'];
if(!isset($tree[$categoryId])){
$tree[$categoryId] = array('id'=>$categoryId ,'name'=>$row['Category']['name'] ,'Items'=>array());
}
$attrib = array('id'=>$row['Attribute']['id'] ,'name'=>$row['Attribute']['name'],'type'=>$row['Attribute']['type']);
if(isset($items[$item_id])){
if($asset = ifExist($assets ,$item_id)){
if(!isset($tree[$categoryId]['Items'][$item_id])){
$tree[$categoryId]['Items'][$item_id] = array('id'=>$item_id ,'name'=>$row['Item']['model']);
}
if(!isset($tree[$categoryId]['Items'][$item_id]['Assets'])){
$tree[$categoryId]['Items'][$item_id]['Assets'] = array('id'=>$asset['id'] ,'name'=>$asset['serial'] ,'Attributes'=>array());
}
if(!isset($tree[$categoryId]['Items'][$item_id]['Assets']['Attributes'][$attr_id])){
$tree[$categoryId]['Items'][$item_id]['Assets']['Attributes'][$attr_id] = $attrib;
}
if($option_id = ifExist($row ,'AttributeOptions' ,'id')){
if(!isset($tree[$categoryId]['Items'][$item_id]['Assets']['Attributes'][$attr_id]['options'])){
$tree[$categoryId]['Items'][$item_id]['Assets']['Attributes'][$attr_id]['options'] = array();
}
$tree[$categoryId]['Items'][$item_id]['Assets']['Attributes'][$attr_id]['options'][$option_id] = $row['AttributeOptions']['label'];
}
}
}else{
if(!isset($tree[$categoryId]['Items'][$item_id])){
$tree[$categoryId]['Items'][$item_id] = array('id'=>$item_id ,'name'=>$row['Item']['model'] ,'Attributes'=>array());
}
if(!isset($tree[$categoryId]['Items'][$item_id]['Attributes'][$attr_id])){
$tree[$categoryId]['Items'][$item_id]['Attributes'][$attr_id] = $attrib;
}
if($option_id = ifExist($row ,'AttributeOptions' ,'id')){
if(!isset($tree[$categoryId]['Items'][$item_id]['Assets']['Attributes'][$attr_id]['options'])){
$tree[$categoryId]['Items'][$item_id]['Attributes'][$attr_id]['options'] = array();
}
$tree[$categoryId]['Items'][$item_id]['Attributes'][$attr_id]['options'][$option_id] = $row['AttributeOptions']['label'];
}
}
}
if(isset($tree)){
foreach($tree as $key=>$items){
if(!ifExist($items ,'Items')){
unset($tree[$key]);
}
}
return $tree;
}
}
debug($items);to see what structure the$itemsarray has?find('list')call returns. No offense, but that's CakePHP basics, and SO isn't really the place to teach stuff like that.