問題描述
將參數傳遞給顏色框 (pass parametres to colorbox)
I am using a colorbox.
<a class="publishpost" href="<?= base_url()."publish_ads/publishon/".$adds[$i]‑>getId()?>"></a>
<script>
$(document).ready(function(){
$('.publishpost').colorbox({ width: '900px', height: '500px' });
});
</script>
I have this link that points to a codeigniter controller. I would like to access some variable from the view in which I load the colorbox. How can I do this. I thought about a form or maybe something with jquery but I still dont know how pass the parametres.
The values that I intend to pass as parametres are something like this for example:
<div class="external_wall_right_col_sub_ad_img"><img src="<?=$img?>" alt="small ad"></div>
I want to pass the $img variable to the colorbox.
‑‑‑‑‑
參考解法
方法 1:
I am answering my own question:
I use the data parameter of the colorbox which sends the data through post.
方法 2:
Determining how you want the front‑end to work is up to you‑‑passing the data, however, I can help you with.
If you choose to use a form, you can access the form data in your controller that you are submitting to. From there you can define the $img variable as such:
$data['img'] = $this‑>input‑>post('input_name');
Then when you load your view, pass the data:
$this‑>load‑>view('view_name', $data);
This will pass all variables declared inside $data to your view. You can now access that variable in your view as you would like:
<img src="<?php echo $img; ?>" alt="small ad">
(by Borut Flis、Borut Flis、Devin Young)