title: User view count in yii
body: <p>I created a button to generate a popup which shows some events.And past few days I was trying to show the count of users which visted the events.<br>
  I tried some of the extensions too...Like </p>
  
  <ol>
  <li>Counter</li>
  <li>pcviewcounter
  etc,</li>
  </ol>
  
  <p>But I need to store the ip address ,eventid  and time in my database.<br>
  Can anyone please help me with this???</p>
  
  <p><strong>View for button</strong></p>
  
  <pre><code>  &lt;div class="modal fade" id="detailsOffeEve" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"&gt; 
  &lt;/div&gt; 
  
  
  &lt;script&gt;
  
          function showdetails(id)
          {   // alert(id); 
          $('#detailsOffeEve').load('&lt;?php echo Yii::app()-&gt;baseUrl; ?&gt;/offerEvents/popup/'+id);
          }
  
  &lt;/script&gt;
  </code></pre>
  
  <p>And <strong>action popup</strong></p>
  
  <pre><code> public function actionPopup($id)
  {   
  
       //$this-&gt;render('/offerEvents/Details',array( 
      //'model'=&gt;OfferEvents::model()-&gt;findByAttributes(array('id'=&gt;$id)), )); 
  $OfferEventsList = OfferEvents::model()-&gt;findAllByAttributes(array('id' =&gt; $id));
  foreach($OfferEventsList as $Listdata)
  {    $titnw=$Listdata['title'];  $details=$Listdata['description']; 
       $discountper=$Listdata['discountper'];   $discountperamt=$Listdata['discountperamt'];  
       $strdaate=$Listdata['startdate']; $enddaate=$Listdata['enddate'];   $evoftype=$Listdata['type'];   }
       $cmuserid=$Listdata['createdby'];       
       if($Listdata['createdby']==0){ $createdbyname="Admin";  }  else { $createdbyname=$Listdata-&gt;company-&gt;companyname; }
       $locationnw=$Listdata-&gt;location;   
       $offrimage=$Listdata-&gt;image;    
  
          if($offrimage!=""){ $imgUrls=$offrimage;  } else { $imgUrls='image-not-available.png'; }
          $infowinimgpaths='theme/images/OfferEvents/orginal/'.$imgUrls;
          if (file_exists($infowinimgpaths)) {  $infowinimgpathSrcs=Yii::app()-&gt;baseUrl.'/'.$infowinimgpaths;   } else 
          {  $infowinimgpathSrcs=Yii::app()-&gt;baseUrl.'/theme/images/OfferEvents/image-not-available.png';   }  
  
  if (Yii::app()-&gt;user-&gt;id!='' &amp;&amp; Yii::app()-&gt;user-&gt;id!=1){ 
  $subcribeemailid=Yii::app()-&gt;user-&gt;email;  $logsts=1;
  $countsubscribe = Newsfeeds::model()-&gt;countByAttributes(array('emailid' =&gt; $subcribeemailid,'cuserid' =&gt; $cmuserid)); 
  } else { $subcribeemailid=''; $countsubscribe=0;  $logsts=0; }  
  
       $PopupdetailText='&lt;div class="modal-dialog-1"&gt;
      &lt;div class="modal-content"&gt;
          &lt;div class="modal-header login_modal_header"&gt;
              &lt;button type="button" class="close" data-dismiss="modal" aria-hidden="true"&gt;&amp;times;&lt;/button&gt;
              &lt;h2 class="modal-title" id="myModalLabel"&gt;'.$titnw.' &lt;/h2&gt;
          &lt;/div&gt;
          &lt;div class="container-1"&gt;
          &lt;div class="row"&gt;
  
          &lt;div class="col-sm-7 detail-text"&gt;
          &lt;h2 class="title"&gt; ';
          if($evoftype==0){ $PopupdetailText.='Offer Price: '.$discountperamt.'
          &lt;font style="font-size: 15px;"&gt;[ Up To '.$discountper.'% Discount ]&lt;/font&gt;';   }
          $PopupdetailText.='&lt;/h2&gt;&lt;p&gt;Details: &lt;/p&gt;
          &lt;p&gt;&lt;a href="#"&gt;'.$details.'&lt;/a&gt;&lt;/p&gt;
          &lt;p&gt;Location: &lt;a href="#"&gt;'.$locationnw.'&lt;/a&gt;&lt;/p&gt;
          &lt;p&gt;Expires in: &lt;a href="#"&gt;'.$enddaate.'&lt;/a&gt;&lt;/p&gt;';
  
  
          if($countsubscribe==0){
          $PopupdetailText.='&lt;p&gt;Shared by: &lt;a href="#" style="font-weight: bold;"&gt;'.$createdbyname.'&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
          &lt;button type="button" class="btn btn-success btn-xs" Onclick="subcribefeed('.$logsts.','.$cmuserid.')" &gt;Subscribe NewsFeed&lt;/button&gt;&lt;/p&gt;';
          } else {
          $PopupdetailText.='&lt;p&gt;Shared by: &lt;a href="#" style="font-weight: bold;"&gt;'.$createdbyname.'&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
          &lt;button type="button" class="btn btn-success disabled btn-xs"   &gt;Already Subscribed NewsFeed&lt;/button&gt;&lt;/p&gt;';
          }
  
          $PopupdetailText.='&lt;div class="form-group" id="subcribefrm" style="display:none;background-color: #eee; padding: 12px; width: 82%;"&gt;
           &lt;input type="text" id="subemailid" placeholder="Enter EmailID here" value="'.$subcribeemailid.'" style="width: 100%;" class="form-control login-field"&gt;
           &lt;br/&gt;
           &lt;a href="#" Onclick="subcribefeedAdd('.$cmuserid.')" class="btn-new btn-login  btn-sm" style="  padding: 6px 18px !important;"&gt;Subscribe Feeds&lt;/a&gt; &lt;/div&gt; ';
  
        //  if($evoftype==0){ $PopupdetailText.='&lt;p&gt;Offer Price:&lt;b&gt; $'.$discountperamt.'&lt;/b&gt;&lt;/p&gt;';  }
  
          $PopupdetailText.='&lt;p&gt;';
          $PopupdetailText .= $this-&gt;renderPartial('/comments/share', array('postid' =&gt; $id),TRUE);       
          $PopupdetailText.='&lt;a href="#"&gt;&lt;img src="'.Yii::app()-&gt;baseUrl.'/theme/site/images/comments.png"/&gt;Comments&lt;/a&gt;
          &lt;a href="#"&gt;&lt;img src="'.Yii::app()-&gt;baseUrl.'/theme/site/images/share.png"/&gt;Share&lt;/a&gt;&lt;/p&gt;
          &lt;br/&gt;';
                  $userComment = new Comments; 
  
                  $PopupdetailText .= $this-&gt;renderPartial('//comments/_form', array('model' =&gt; $userComment,'id'=&gt;$id),TRUE,TRUE);
                  // $PopupdetailText .= $this-&gt;renderPartial('//comments/view', array('model' =&gt; $userComment,'id'=&gt;$id),TRUE);
  
                  $PopupdetailText.='&lt;/div&gt;
  
  
  
          &lt;div class="col-sm-5"&gt;
          &lt;img src="'.$infowinimgpathSrcs.'" width="100%"/&gt;
          &lt;/div&gt;
          &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class="clearfix"&gt;&lt;/div&gt;
          &lt;div class="modal-footer login_modal_footer"&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt; 
  &lt;script&gt; 
      function subcribefeed(staus,cid)
      {   
      if(staus==0){ 
        $("#subcribefrm").toggle();  }
        else {    subcribefeedAdd(cid);     }
      }
  
      function subcribefeedAdd(cid)
      {    
      subusremail=$("#subemailid").val();   
  
  var re = /[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}/igm;
  if (subusremail == "" || !re.test(subusremail))
  {   alert("Invalid EmailID .");   } 
  else { 
          postData ={
          "email" :subusremail,  
          "cid" :cid  
          }
          $.ajax({
          type: "POST",
          data: postData ,
          url: "'.Yii::app()-&gt;baseUrl.'/newsfeeds/create",
          success: function(msg){    
            if(msg=="Success"){ showdetails('.$id.');  alert("news feed subscribe successfully.");  }  
            else if(msg=="available"){ alert("Already subscribe News Feed for this Commercial user."); }
            else { alert("Error ."); }             
          }
          });
  }
  
      } 
  &lt;/script&gt; '; 
  
      echo $PopupdetailText;  
  } 
  </code></pre>