PHP in Javascript problem

Hi guys

I want to use zaccaria’s Dialog and javascript function (see it here) for other actions as well. So I need to be able to send the relevant action name to the function. Something like:




<script type="text/javascript">

function addClassroom(myAction)

{

   myUrl = 'controllername/' + myAction


   <?php echo CHtml::ajax(array(

      'url'=>array("js:myUrl"),

      ...



The problem is using myUrl in CHtml::ajax.

‘url’=>array(“js:myUrl”) does not work.

Regards

Hi Gerhard,

Recently I had the same challenge and I found out that I had to include the path to my application. So it should look something like this:


url = '/appname/index.php/controller/action'

Hope that helps!

Hi Xajaccio

Thanx for the reply.

I got the Create action working (obviously, because that is the wiki).

Now I want to use the same functionality for the CGridView’s ‘update’ buttons.

So I need to pass the url and PK to the javascript function.

I’ve spoken with zaccaria and he suggests generating the url outside the javascript function (in the link or in the CGridView) and then referring to it inside the function with javascript such as “div.find(‘a.createLink’).attr(‘href’);”. So you don’t “pass” it to the function like I tried to do.

I belief, this approach boils down to the same thing you are saying.

Regards

Gerhard