dousuo2812 2016-05-17 12:02
浏览 114
已采纳

在yii2上使用Pjax时出错

I am trying to implement content autoload wit the aid of pjax on yii2 but I get Uncaught TypeError: jQuery(...).pjax is not a function. I can't solve it. This is my view file:

<?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>

This is action in 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条回答 默认 最新

  • duannao8450 2016-05-18 07:29
    关注
    1. Make sure of you installed 'fxp/composer-asset-plugin' corrently.

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

    2. Check the folder 'vender/bower/yii2-pjax', if it doesn't exists, run

      composer install

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 根据以下文字信息,做EA模型图
  • ¥15 删除虚拟显示器驱动 删除所有 Xorg 配置文件 删除显示器缓存文件 重启系统 可是依旧无法退出虚拟显示器
  • ¥15 vscode程序一直报同样的错,如何解决?
  • ¥15 关于使用unity中遇到的问题
  • ¥15 开放世界如何写线性关卡的用例(类似原神)
  • ¥15 关于并联谐振电磁感应加热
  • ¥60 请查询全国几个煤炭大省近十年的煤炭铁路及公路的货物周转量
  • ¥15 请帮我看看我这道c语言题到底漏了哪种情况吧!
  • ¥60 关机时蓝屏并显示KMODE_EXCEPTION_NOT_HANDLED,怎么修?
  • ¥66 如何制作支付宝扫码跳转到发红包界面