Javacript Debugging With Renderpartial

Hello;

I try to debug a javascript code which is called from a view which is called by renderpartial function. However, my breakpoints in the javascript file are useless since yii transforms the js code to a file VMXXX and makes the function call to this file. I can see it from the call stack.

Does anyone know how to debug javascript code called from a partially rendered view php?

Thanks

Hi nacis,

Do you try to debug a javascript in a PHP IDE like Eclipse or NetBeans?

I think it’s easier to debug it in a developer’s tool of your browser.

Thanks for the answer,

Actually I debug it in Chrome Developer Toolkit. My problem is when I set a breakpoint in the JS file. It is invalid since yii uses it’s own transformed js file. This is caused by renderpartial. I know because when I call the view directly with url ?r=site/ControllerAction, it includes the original JS file.

I don’t understand this part:

As far as I know, yii won’t do it by itself.

And even if the actual script file had been VMXXX, it would have appeared in the source list of Chrome’s dev tool.

Do you use CClientScript::registerXXX to render the script in your partial view?

And are you calling renderPartial in an ajax response?

  1. I have a js file link in my view. I include it by adding

<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/EABlueprint.js"></script>

then I have a function call in the view

<script type="text/javascript">

    initEAProjects(); //this function is inside EABlueprint.js

</script>

I don’t use CClientScript::registerXXX code.

  1. I have a CHtml Link which calls the controller and puts the rendered view inside container.

<?php

    echo CHtml::ajaxLink('&lt;i class=&quot;icon-book&quot;&gt;&lt;/i&gt;Project Details', CController::createUrl('site/projectdetails'), array('update' =&gt; '#secondcontainer'),array('id'=&gt;'projectdetails'));


    ?&gt;
  1. My controller includes :

$this->renderPartial(‘processdetails’, array(), false, true); //this is the view php file.

All works great. The result is as I expected. JS is included and initEAProjects() function is executed.

However when I set a breakpoint inside the initEAProjects() function, the execution does not break, although it does when I use render instead of renderpartial.

Thanks.

My guess is that you are loading EABlueprint.js multiple times, again and again with each ajax call. So the code that you have set a break point will not be called after an ajax, but the same code newly loaded will be called instead.

Do you really have to load the script in every ajax response? Maybe no, I guess.

Consider using registerScriptFile, then you can load the script just once in the initial page load.