Fuel\Core\PhpErrorException [ Warning ]: array_key_exists(): The first argument should be either a string or an integer

747 views Asked by At

Trying to get a drop down list to be populated with a category name when the category id is entered. I get an error unfortunately. The SQL that is returned should be an integer for the key and a string for the value. However, the warning says it is not. I've checked the output of my query to the screen to double check that it is indeed an integer/string.

view: content.php

<label for="category">Category</label>
<form action="content.php" method="post">
<input type="<?php Input::post($data['id']) ?>" name="category" ><br />

<br />


<div class=" form-group">
<div class=" form-group">
<select class="form-control form-control-sm">
<?php
                                                            Input::get($data['id']);
foreach($data as $option){ ?>
<option><?= $option['name'] ?></option>
 <?php } ?> 
</select>

controller: shelf.php

class Controller_Shelf extends Controller
{
    public function action_index()
    {
        $model = new Model_Shelf();
        $data = $model->get_results();
        // create the layout view
        $view = View::forge('shelf/index');

        // assign global variables so all views have access to them
        /* $view->data = $result; */


        //assign views as variables, lazy rendering
        $view->head = View::forge('common/head');
        $view->header = View::forge('common/header');
        $view->content = View::forge('common/content', array('data'=>$data));
        $view->footer = View::forge('common/footer');

        // return the view object to the Request
        //return $view;
        return Response::forge($view);
    }

    public function post_index()
    {
        // This will be called when the HTTP method is POST.
    }

}

model: shelf.php

class Model_Shelf extends \Model 
{    
    public static function get_results()
    {
        /* $result = DB::query('select substring(cat.item_class_cd,1,1) as id, cat.class_name as name
        from MASTER_DB.MS_CATEGORY cat
        where length(cat.item_class_cd) = 1')->execute(); */
        // doesn't work
        $result = DB::query('select cast(cat.item_class_cd as decimal) as id, cat.class_name as name
        from MASTER_DB.MS_CATEGORY cat
        where length(cat.item_class_cd) = 1')->execute();

        return $result;
        //return ['id' => 1, 'name' => 'test']
    }
 } 

The error message is as same as the title.

array_key_exists(): The first argument should be either a string or an integer
COREPATH/classes/arr.php @ line 57

52            return $return;
53        }
54
55        is_object($key) and $key = (string) $key;
56
57        if (array_key_exists($key, $array))
58        {
59            return $array[$key];
60        }
61
62        foreach (explode('.', $key) as $key_part)

How should do I fix this? Thanks for any help. Let me know if you need clarification.

0

There are 0 answers