わかりましたので、通常はこれを行うのに問題はなく、かなり簡単ですが、今回はそれほど問題はありません。
私のコントローラーの関連コードは次のとおりです。
// In order to properly build the form url, we need to include the
// category and product to the view
$this->data = array(
'category' => $category,
'product' => $product
);
// Load the product model and get editable values from the database
$this->load->model('productadmin/products_model');
$productInformation = $this->products_model->get_product_data($product);
// Modular code! Use variable-variables to prevent having to write multiple lines of code
// when we start returning more information from the data
foreach ( $productInformation as $variable => $value )
{
$this->data[$variable] = $value;
}
ここで、$product、$category、および製品モデルから返された変数にアクセスできることが理想的です。print_r を実行すると、次のようになります。
Array ( [category] => 1 [product] => 1 [0] => Array ( [id] => 1 [product_name] => Duff ) )
foreach ステートメントによって生成されたものが独自の配列に含まれていることに注意してください。最も簡単な解決策は、 を渡すだけで、ビューからその 2 番目の配列にアクセスする方法を知ること$this->data
です。
それができない場合、データ配列内に別の配列を作成せずに、データ配列内にモデルの連想値を割り当てるには、何を変更できますか?
このモデルは、get_where ステートメントからキーと値のペアを返すだけです。