0

I am trying to concat between a json object and a cakephp code. to form a valid hyperlink.

this is the json object = item.Customer.customers_name

I want the json object (customer name) to be display in the cakephp hyperlink.

The end result would be

<li class="icn_list_users">
<a href="/admin/scores/edit_test_a_1/345/abcdef/2949/scores">Ty John</a>
</li>

i can't seem top concat js and php together well.

    <script type="text/javascript">

     $.getJSON("http://localhost:8888/tests/teststudents.json?id=<?php echo $this->params['pass'][1]; ?>", function(data) {

      var ul = $('#teststudents');

      $.each(data, function (i, item) {
      ul.append($('<li class="icn_list_users"><?php echo $html->link(' + item.Customer.customers_name + ', array('admin'=> true, 'controller' => 'scores','action' => $scoresheetpath, $this->params['pass'][1],$range)); ?></li>'));
      });

      }); 

    </script>

2 Answers 2

2

You can't combine PHP and javascript. PHP is a server-side language and Javascript is client-side. That means that PHP will be parsed first, sent to the client, and then Javascript will be parsed. If you need to make links in Javascript, do it with jquery. You can set Javascript variables with PHP, but not the other way.

Please also see this question: What is the difference between client-side and server-side programming?

Sign up to request clarification or add additional context in comments.

Comments

0

As the Eagle said, you can't concat both php and json object as the concept is different. But what you can do is some adjustment on your code as below and you can display your list as you need.

    <script type="text/javascript">

     $.getJSON("http://localhost:8888/tests/teststudents.json?id=<?php echo $this->params['pass'][1]; ?>", function(data) {

      var ul = $('#teststudents');

      $.each(data, function (i, item) {
         ul.append('<li class="icn_list_users"><a href="/admin/scores/edit_test_a_1/345/abcdef/2949/scores">' + item.Customer.customers_name + '</a></li>');
      });

      }); 

</script>

Hope it helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.