モジュールの配列にいくつかのオプションを追加する際に問題が発生しました。Opencartを使用していて、画像を追加してモジュールを拡張しようとしています。これを行い、コードが将来何も壊さないようにするために、配列を置き換えるのではなく、配列に追加したいと思いました。
これは私がこれまでに持っているコードです:
if (isset($this->request->post['special_module'])) {
$modules = $this->request->post['special_module'];
} elseif ($this->config->get('special_module')) {
$modules = $this->config->get('special_module');
}
$this->load->model('tool/image');
foreach ($modules as $module) {
if (isset($module['image']) && file_exists(DIR_IMAGE . $module['image'])) {
$image = $module['image'];
} else {
$image = 'no_image.jpg';
}
array_push($module, array(
'image' => $image,
'thumb' => $this->model_tool_image->resize($image, 100, 100)
));
}
print_r($modules);exit;
$this->data['modules'] = $modules;
アレイを印刷します。画像や親指はありません。
Array
(
[0] => Array
(
[image_width] => 307
[image_height] => 234
[layout_id] => 1
[position] => column_right
[status] => 1
[sort_order] => 1
)
)
array_pushを実行するとき、これを配列に割り当てる必要がありますか?