將參數傳遞給顏色框 (pass parametres to colorbox)


問題描述

將參數傳遞給顏色框 (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 FlisBorut FlisDevin Young)

參考文件

  1. pass parametres to colorbox (CC BY‑SA 3.0/4.0)

#jquery #parameters #codeigniter #PHP #colorbox






相關問題

讓 jQuery 與 Netscape 7 和 8 一起工作 (Getting jQuery to work with Netscape 7 and 8)

使用 Jquery 的 mvc3 搜索結果 (mvc3 search results with Jquery)

從嵌套的 jquery 函數返回一個值 (Return a value from nested jquery function)

Mencocokkan lebar divisi dengan jquery (Matching division widths with jquery)

無法在 jQuery AJAX 中多次生成點擊事件 (unable to generate click event more than once in jQuery AJAX)

使用雙引號格式並用逗號分隔元素數組 (Implode an element array with double quote format and separated by comma)

選擇不更新 (Select doesn't update)

chrome中帶有省略號的多行文本問題 (issue with multiline text with ellipsis in chrome)

AJAX/PHP/JS - 無法將頁面內容加載到容器中 (AJAX/PHP/JS - Cannot load page content into container)

使用 jQuery 將文本插入 textarea (Insert text into textarea with jQuery)

滾動到頁面底部,僅當用戶在 DOM 操作之前已經位於底部時 (Scroll to bottom of page, only if the user already was at the bottom before DOM manipulation)

如何設置單選按鈕的樣式,使其看起來像普通的可點擊按鈕? (How do I style a radio button to look like a normal clickable button?)







留言討論