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
Page 1 of 1
Link to method within Portlet class
#2
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) 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.
#3
Posted 06 May 2010 - 03:47 PM
andy_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.
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
Share this topic:
Page 1 of 1

Help












