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.
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.
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.