我是一个新手,想知道是否有任何扩展来计算点击按钮的浏览量,因为不知道。的注册用户或网页访问者知道点击图像的查看次数是否有任何扩展。
请让我知道是否有
谢谢 :)
我是一个新手,想知道是否有任何扩展来计算点击按钮的浏览量,因为不知道。的注册用户或网页访问者知道点击图像的查看次数是否有任何扩展。
请让我知道是否有
谢谢 :)
我认为,不需要任何扩展。在单击按钮或您感兴趣的图像上进行 Ajax 调用。
改进:我假设您将站点作为控制器,将索引作为操作。那么,请将此代码保留在 views/site/index.php 上。
Yii::app()->clientScript->registerScript('logo_as_image_script', '$(document).ready(function() {
$("#logo_as_image").click(function() {
$.post("'.Yii::app()->createAbsoluteUrl('site/index').'",
{
clicked: "1"
},
function(data, status) {
alert("Data: " + data + "\nStatus: " + status);
});
});
});');
Yii::app()->clientScript->registerCoreScript('jquery');
echo CHtml::image(Yii::app()->baseUrl . '/images/logo.png', 'Logo as Image', array('id' => 'logo_as_image'));
并且,将此代码保留在 SiteController.php 上。
public function actionIndex()
{
// keep record of data ; do more filtering ; other manupulation
if(isset($_POST['clicked'])){
$nextCount = Yii::app()->user->getState('clickCount')+1;
Yii::app()->user->setState('clickCount',$nextCount );
echo $nextCount;
Yii::app()->end();
}
#other codes here.
$this->render('index');
}
让我们假设您要存储有多少注册用户访问了该页面:
www.something.com/something/someaction
然后访问控制器并添加如下代码:
public function actionSomeAction()
{
$model = new CountDbModel();
if(!Yii::app()->user->isGuest){
$model->page = 'This page name here.';
$model->user_id = Yii::app()->user->id;
$model->count = #Add the value here.
#You other code here....
$this->render('whateverView',array('model'=>$blah));
}
}
我希望它有所帮助。