Search code examples
cakephpjquery-pluginsflowplayer

Load cakePHP Element from jQuery


I am using cakePHP rating plugin with Flowplayer. I have customized the Flowplayer using the Javascript API. Now I need to display the rating element on the customized Flowplayer. In my other views, I am showing the rating element as given below :

echo $this->element('rating', array('plugin' => 'rating',
        'model' => 'SongDetail',
        'id' =>$song_id,
        'name'=>'songRating',
        'config' => 'plugin_rating'
    ));

and it is working fine. Now inthe case of flowplayer,I am loading songs using AJAX with jQuery and so the song_id variable is available only in Javascript.How can I call this same element from a Javascript function so that this can be inserted using innerHTML.


Solution

  • Make a special action that you call with the song_id as parameter. Then end that action with:

    $this->layout = 'ajax';
    $this->render('/elements/<elementname>');
    

    This will make CakePHP render an element in stead of a view. Using the AJAX layout will mean that it's only the element (and no menus and footers etc) that is rendered.

    See documentation for $this->render in the CakePHP Book.