Replacing link() with ajaxLink()?

Hello - looking for some wisdom -

If I want to change all the links on my site in to Ajax calls - what would be the best way to go about that?

For example:

a standard Yii app uses 'main.php' in the 'layouts' directory as a frame, and content gets echoed from the various pages thru the $content variable -

My question is, how would one go about turning a standard link into a Ajax call that would replace the $content variable (and whatever other elements such as page title)?

Please let me know or if I can provide you with any more details as to what I am trying to do here -

Thanks

Peace

status update:

seem to have got it working to a certain degree, but my target div now gets the entire site delivered to it (so it looks like i have one site inside the other)

i can feel i am getting close to a solution…

here is the code snippet that i used:

<?php echo CHtml::ajaxLink('Check out This Module',array('/ModuleName/'), array(


	'type'=>'POST',


	'update'=>'#center_content',


)); ?>

as you might imagine, there is a div in my main.php file with the id 'center_content'

the question now: how do i NOT include all the drama surrounding this div?

a renderPartial perhaps?

Hello backgammon ,

your are on the right way:

You have to detect in the controller action-method

if it is an ajax-request [maybe you can use CHttpRequest->isAjaxRequest() ]

and if so you call renderPartial, otherwise you call render…

I don't have tried it yet, but i think this should be the way…

Greetings

me23

ahh - excellent suggestion -

i will be trying to figure this out throughout the day -

thanks a lot -

[move]status update:[/move]

there is something working here - which is great -

applied this code to my controller:

<pre class='prettyprint'>public function actionHarth() 


{





	if(Yii::app()-&gt;request-&gt;isAjaxRequest)


	{


		$this-&gt;renderPartial(&#039;harth&#039;,NULL,false);		


	}


	


}</pre>

and adjusted the initial ajaxLink() so that it was calling the appropriate view (in this case the Harth view):

<?php echo CHtml::ajaxLink('Check out This Module',array('/ModuleName/model/harth/'), array(


	'type'=>'POST',


	'update'=>'#center_content',


)); ?>

so this is working nicely now - the only problem is that none of the javascripts that i had in my view are working -

they were applied at the top of the view this way for example:

<?php 


$cs=Yii::app()->clientScript;





$cs->registerScriptFile(Yii::app()->request->baseUrl.'/js/custom/jquery.textdropdown.js', CClientScript::POS_BEGIN);


?>


any insights as to what i could do next?

please let me know any insights you may have

thanks for the help

Peace