单击按钮时如何运行 yii 小部件 [英] how to run yii widget when button clicked

查看:29
本文介绍了单击按钮时如何运行 yii 小部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个小部件:

compare('fileName', $_GET['file'], true, 'OR');$criteria->compare('tags', $_GET['file'], true, 'OR');}$this->dataProvider = new CActiveDataProvider("文件", array('标准' =>$标准,//'countCriteria' =>$标准,'分页'=>数组(//每页结果'pageSize'=>1,),));}公共函数运行(){$this->render('site/result', array('数据提供者' =>$this->dataProvider,'页面' =>$this->dataProvider->分页,));}}?>

如何仅在单击搜索按钮时运行此小部件,以及如何在位于文件夹站点中的视图 reuslt 中查看其结果

解决方案

也许我误解了你,但我认为你对小部件有点困惑.避免制作
冗长的答案,我在下面做了一个模型

<块引用>

问题 1:如何仅在单击搜索按钮时运行此小部件?

思路是把widget的内容放到隐藏的div中,然后添加一个jQuery脚本,在搜索按钮点击后显示

<div id='search-result' style="display:none"><?php $this->widget(...) ?></div><脚本>$('#search-button-id').click({//做点什么$('#search-result').show();})

<块引用>

问题2:如何在位于文件夹站点的视图结果中查看其结果?

Imao,我建议你不要这样做.小部件是独立的部分,您可以将其用于许多特定目的 &项目的许多位置,因此只需为小部件放置一个简单的视图即可在其自身中呈现,而不是尝试呈现小部件范围之外的视图.它应该如下所示

/your-app/protected/extensions/widgets/search/Search.php/your-app/protected/extensions/widgets/search/views/result.php//渲染视图

I have this widget:

<?php

    class Search extends CWidget
    {
        public $dataProvider = null;
        public function init()
        {
            $criteria = new CDbCriteria();

                if ( isset($_GET['file']) ) {
                    $criteria->compare('fileName', $_GET['file'], true, 'OR');
                    $criteria->compare('tags', $_GET['file'], true, 'OR');
                }

                $this->dataProvider = new CActiveDataProvider("Files", array(
                    'criteria' => $criteria,
                    //'countCriteria' => $criteria,
                    'pagination'=>array(
                        // results per page
                        'pageSize'=>1,
                    ),
                ));
        }

        public function run(){
        $this->render('site/result', array(
                    'dataProvider' => $this->dataProvider,
                    'pages' => $this->dataProvider->pagination,
                ));
        }
    }
    ?>

how I can run this widget only when the search button is clicked, and how to view its result in the view reuslt that is located in the folder site

解决方案

Maybe I misunderstood you, but I think you have a little confusion about widget. Avoid making a
lengthy answer, I made a model in below

Question 1: How I can run this widget only when the search button is clicked?

The idea is that you put the widget content into hidden div, and then add a jQuery script to show it after the search button is clicked

<div id='search-result' style="display:none"><?php $this->widget(...) ?></div>
<script>
$('#search-button-id').click({
// do something
$('#search-result').show();
})</script>

Question 2: how to view its result in the view reuslt that is located in the folder site?

Imao, I recommend you don't do this. The widget is independant part, you can use it for many specific purposes & many locations of your project, so just put a simple view for widget to render in its own, instead of trying to render a view outside widget's scope. It should look like below

/your-app/protected/extensions/widgets/search/Search.php
/your-app/protected/extensions/widgets/search/views/result.php // view for rendering

这篇关于单击按钮时如何运行 yii 小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆