Yii Framework Forum: Link to method within Portlet class - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Link to method within Portlet class Rate Topic: -----

#1 User is offline   YIINewBy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 41
  • Joined: 11-September 09
  • Location:Pretoria, South Africa

Posted 05 May 2010 - 03:05 PM

I have the following situation, I'm implementing a portlet that displays adds.

Now I'm rendering a img with a link in the portlet view. Now evertime a visitor clicks on the add it needs to call a method within the portlet that performs an action and then links to the relevant website of the ad.


Here's my code that is displayed in the view

CHtml::link(CHtml::image(CHtml::encode($row['img_path']),$row['title'],array('width'=>'210','height'=>'59','border'=>'0')),array('WHAT GOES HERE'),array('title'=>$row['title'].' - '.$row['url']));

The method name is countClicks() that needs to be called. Please advise
0

#2 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 06 May 2010 - 12:32 AM

I see two solutions:

1) CHtml::link(image, array('/controllerA/actionB', 'ad'=>$row['url']), array). On click you will go to actionB of controllerA, so you can put any code there and then redirect to $_GET['ad']. Of course, you can pass more parameters, e.g. $row['id'], if your ads are stored in the db and have ids.

2) AJAX solution, but actually the same idea. Create a JS function which will be called when a user clicks on a link. Inside this function you should send an info about the clicked ad to controllerA/actionB and perform desired operations without any redirects.
1

#3 User is offline   YIINewBy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 41
  • Joined: 11-September 09
  • Location:Pretoria, South Africa

Posted 06 May 2010 - 03:47 PM

View Postandy_s, on 06 May 2010 - 12:32 AM, said:

I see two solutions:

1) CHtml::link(image, array('/controllerA/actionB', 'ad'=>$row['url']), array). On click you will go to actionB of controllerA, so you can put any code there and then redirect to $_GET['ad']. Of course, you can pass more parameters, e.g. $row['id'], if your ads are stored in the db and have ids.

2) AJAX solution, but actually the same idea. Create a JS function which will be called when a user clicks on a link. Inside this function you should send an info about the clicked ad to controllerA/actionB and perform desired operations without any redirects.



Thanx for the reply, problem solved.


http://www.techportal.co.za
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users