簡體   English   中英

在yii2上使用Pjax時出錯

[英]Error using Pjax on yii2

我試圖在yii2上借助pjax實現內容自動加載,但出現Uncaught TypeError:jQuery(...)。pjax不是一個函數。 我解決不了 這是我的視圖文件:

<?php
    use yii\widgets\Pjax;
    use yii\helpers\Html;
?>
<title>Web-shop</title>
</head>
<body>
<div class="sort-panel">
                <div class="container">
                    <div class="sort">
                        <p><span class="hidden-xs">Sort by:&nbsp;</span>
                            <?php Pjax::begin([]); ?><span class="sorter active-sorter">
                                <?= Html::a(
                                'name&nbsp;',
                                ['site/inner', 'action' => 'name'],
                                ['class' => 'sorter  name']
                                ) ?>

                                <span class="glyphicon glyphicon-chevron-down"></span>
                            </span>&nbsp;|&nbsp;<?php Pjax::end(); ?>

                            <?php Pjax::begin([]); ?><span class="sorter"><?= Html::a(
                                'price&nbsp;',
                                ['site/inner', 'action' => 'price'],
                                ['class' => 'sorter name']
                                ) ?>
                                <span class="glyphicon"></span>
                            </span>&nbsp;|&nbsp;<?php Pjax::end(); ?>
                            <?php Pjax::begin([]); ?><span class="sorter"><?= Html::a(
                                'date&nbsp;',
                                ['site/inner', 'action' => 'date'],
                                ['class' => 'sorter  name']
                                ) ?>
                                <span class="glyphicon"></span>
                            </span>&nbsp;|&nbsp;<?php Pjax::end(); ?>
                            <?php Pjax::begin([]); ?><span class="sorter"><?= Html::a(
                                'popularity&nbsp;',
                                ['site/inner', 'action' => 'popularity'],
                                ['class' => 'sorter  name']
                                ) ?>
                                <span class="glyphicon"></span>
                            </span><?php Pjax::end(); ?>
                        </p>
                    </div>
                    <div class="view hidden-xs">
                        <span class="glyphicon glyphicon-th active-view"></span>&nbsp;
                        <span class="glyphicon glyphicon-th-list"></span>
                    </div>
                    <div class="clear"></div>
                </div>
            </div>
        <div class="container inner-content push">
           <?php  foreach ($posts as $post) { ?>
            <div class="event-list">
                <a href="#" class="image-wrapper event-list-image col-sm-4" style="background-image: url(events/party-girls.jpg);"></a>
                <div class="event-list-content col-sm-8">
                    <div class="col-xs-6 event-list-heading">
                        <h1><a href="#"><?=$post->title?></a></h1>
                        <p class="event-list-date"><?=$post->date?></p>                    
                    </div>
                    <p class="col-xs-6 event-list-price"><?=$post->price?></p>
                    <div class="clear"></div>
                    <div class="event-list-desc">
                        <?=$post->full_text?>

                        <a href="<?=$post->link?>" class="go_to">Go to</a>

                    </div>
                </div>
                <div class="clear"></div>
            </div>
           <?php } ?>
        <div class="clear"></div>    
        <?php Pjax::begin(['enableReplaceState' => false]);
        $a = $a +1;?>
            <?= Html::a(
                                'Load More',
                                ['site/inner', 'action' => $action,'a' => $a],
                                ['class' => 'load-more']
                                ) ?><?php Pjax::end(); ?>
        </div>
        <div class="clear"></div>
</body>
</html>

這是Sitecontroller中的操作:

public function actionInner($action = '', $a = 0)
    {
        $posts = Event::find()->limit(5 + $a*3)->all();
foreach ($posts as $post) {
            $post->price = $post->price - $post->price * $post->discount/100;
        }
        if ($action === 'name') {
            $posts = Event::find()->limit(5 + $a*3)->orderBy(['title' => SORT_ASC])->all();
        foreach ($posts as $post) {
            $post->price = $post->price - $post->price * $post->discount/100;
        }
            }
        $news = Event::find()->limit(5 + $a*3)->orderBy(['date' => SORT_DESC])->all();
        $populars = Event::find()->where(['is_popular'=> 1])->limit(5 + $a*3)->orderBy(['likes' => SORT_DESC])->all();

        return $this->render('inner',[
            'posts' => $posts,
            'time' => date('H:i:s'),
            'a' => $a,
            'action' => $action
        ]);
    }
  1. 確保正確安裝了“ fxp / composer-asset-plugin”。

    composer global require "fxp/composer-asset-plugin:~1.1.3"

  2. 檢查文件夾“ vender / bower / yii2-pjax”,如果不存在,請運行

    composer install

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM