Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I extended the TbTabs class with @Abdullahs example. It's tested with <a href="http://www.yiiframework.com/extension/yiibooster/" rel="nofollow">YiiBooster</a>, but should work with other Bootstrap plugins as well.</p> <p>Usage:</p> <pre><code>$this-&gt;widget( 'ext.ajaxTabs.widgets.ajaxTabs', array( 'reload' =&gt; true, // Reload the tab content each time a tab is clicked. Delete this line to load it only once. 'tabs' =&gt; array( array( 'label' =&gt; 'Static', 'content' =&gt; 'Static content' ), array( 'label' =&gt; 'Static rendered', 'content' =&gt; $this-&gt;renderPartial('index', null, true), ), // And finally AJAX: array( 'label' =&gt; 'AJAX', 'content' =&gt; 'loading ....', 'linkOptions' =&gt; array('data-tab-url' =&gt; Yii::app()-&gt;createAbsoluteUrl('site/')) ) ), ) ); </code></pre> <p>/protected/extensions/ajaxTabs/widget/ajaxTabs.php:</p> <pre><code>&lt;?php Yii::import('bootstrap.widgets.TbTabs'); class ajaxTabs extends TbTabs { /** * @var bool Reload the tab content each time the tab is clicked. Default: load only once */ public $reload = false; public function run() { $id = $this-&gt;id; /** @var CClientScript $cs */ $cs = Yii::app()-&gt;getClientScript(); $cs-&gt;registerScript( __CLASS__ . '#' . $id . '_ajax', ' function TbTabsAjax(e) { e.preventDefault(); var $eTarget = $(e.target); var $tab = $($eTarget.attr("href")); var ctUrl = $eTarget.data("tab-url"); if (ctUrl != "" &amp;&amp; ctUrl !== undefined) { $.ajax({ url: ctUrl, type: "POST", dataType: "html", cache: false, success: function (html) { $tab.html(html); }, error: function () { alert("Request failed"); } }); } if(' . ($this-&gt;reload ? 0 : 1) . '){ $eTarget.data("tab-url", ""); } return false; }' ); $this-&gt;events['shown'] = 'js:TbTabsAjax'; parent::run(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload