1

プロジェクトで Phalcon の Volt エンジンを使用すると、奇妙な PHP エラーが発生します。ケースは非常に単純に見えますが、コードを何度もチェックしましたが、単純な if-elseif-endif 構造を動作させることができないようです。

テンプレート コードはここにあり、jQuery callcack 関数のコンテキストで Javascript ブロックに配置されます。

{% if table.form.rendered_in == 'offcanvas' %}
            //offcanvas form
            //set attributes

            $(row).find('td.edit-control').

                attr('data-source', '{{table.form.full_action_url}}?get_form').
                attr('data-canvas', 'body').
                attr('data-target', '#rightSlider').
                attr('data-toggle', 'offcanvas').

                click(function () { 
                    console.log('! show edit form: '+record_id);    
                    //edit_one(record_id);
                    if (!right_offcanvas_visible) {

                        //request form with ajax
                        var url = $(this).attr('data-source');
                        var data = {
                            'choose_record': [record_id]
                        };

                        //console.log('Serialized data: '+data);    
                        //$('div#rightSlider').offcanvas('show');
                        TASK.Ajax.Post(url, data, function(response) {  
                            $('div#rightSlider').find('div.rightSliderContent').html(response);
                            //$('div.offcanvas').offcanvas({canvas: 'body'}); // todo: make it work!
                            console.log('! edit one record form set up');    
                        });

                    }

                });

            //delete    
            $(row).find('td.delete-control').

                attr('data-source', '{{table.form.full_action_url}}?get_delete_form').
                attr('data-canvas', 'body').
                attr('data-target', '#rightSlider').
                attr('data-toggle', 'offcanvas').

                click(function () { 
                    if (!right_offcanvas_visible) {

                        //request form with ajax
                        var url = $(this).attr('data-source');
                        var data = {
                            'choose_record': [record_id]
                        };

                        TASK.Ajax.Post(url, data, function(response) {  
                            $('div#rightSlider').find('div.rightSliderContent').html(response);
                        });

                    }

                });

        {% elseif table.form.rendered_in == 'page' %}
            //on same page above the table

            $(row).find('td.edit-control').
                attr('data-source', '{{table.form.full_action_url}}?get_form').
                click(function () { 
                    console.log('! show edit form above table: '+record_id);    
                    var url = $(this).attr('data-source');
                    var data = {
                        'choose_record': [record_id]
                    };

                    TASK.Ajax.Post(url, data, function(response) {  
                        $('div#form-page-main').html(response);
                        $('html, body').animate({ //scroll smoothly to form
                            scrollTop: $('div#form-page-main').offset().top - config.scrollDistanceFromTop
                        }, config.timeAnimateToAjaxForm);
                    });

                });            


            $(row).find('td.delete-control').
                attr('data-source', '{{table.form.full_action_url}}?get_delete_form').
                click(function () { 
                    console.log('! show delete form above table: '+record_id);    
                    var url = $(this).attr('data-source');
                    var data = {
                        'choose_record': [record_id]
                    };

                    TASK.Ajax.Post(url, data, function(response) {  
                        $('div#form-page-main').html(response);
                        $('html, body').animate({ //scroll smoothly to confirmation
                            scrollTop: $('div#form-page-main').offset().top - config.scrollDistanceFromTop
                        }, config.timeAnimateToAjaxForm);
                    });

                });

        {% elseif table.form.rendered_in == 'modal' %}
            // rendered in modal window

            $(row).find('td.edit-control').
                attr('data-source', '{{table.form.full_action_url}}?get_form').
                attr('data-target', '#largeModal').
                attr('data-toggle', 'modal').
                click(function () { 
                    console.log('! show edit form in modal: '+record_id);    
                    var url = $(this).attr('data-source');
                    var data = {
                        'choose_record': [record_id]
                    };

                    TASK.Ajax.Post(url, data, function(response) {  
                        $('div#largeModal').find('div.modal-body').html(response);
                    });

                });            


            $(row).find('td.delete-control').
                attr('data-source', '{{table.form.full_action_url}}?get_delete_form').
                attr('data-target', '#smallModal').
                attr('data-toggle', 'modal').
                click(function () { 
                    console.log('! show delete form in modal: '+record_id);    
                    var url = $(this).attr('data-source');
                    var data = {
                        'choose_record': [record_id]
                    };

                    TASK.Ajax.Post(url, data, function(response) {  
                        $('div#smallModal').find('div.modal-body').html(response);
                    });

                });

        {% endif %}

このエラーは、最初に Volt コンパイラによって生成される可能性があります。それ以外の場合は、以下で参照すると、volt ファイルが PHP にコンパイルされません。

{% elseif table.form.rendered_in == 'page' %}

エラーの 内容: 307 行目の .../app/views/partials/grideditor.volt の予期しない ENDIF

if-elseif-endif 構造は、Javascript ブロックの他の場所でうまく機能します。以下のように、elseif を複数の if-endif、if-endif に置き換えると、すべてが正常に機能します。

{% if table.form.rendered_in == 'offcanvas' %}
            //offcanvas form
            //set attributes

            $(row).find('td.edit-control').

                attr('data-source', '{{table.form.full_action_url}}?get_form').
                attr('data-canvas', 'body').
                attr('data-target', '#rightSlider').
                attr('data-toggle', 'offcanvas').

                click(function () { 
                    console.log('! show edit form: '+record_id);    
                    //edit_one(record_id);
                    if (!right_offcanvas_visible) {

                        //request form with ajax
                        var url = $(this).attr('data-source');
                        var data = {
                            'choose_record': [record_id]
                        };

                        //console.log('Serialized data: '+data);    
                        //$('div#rightSlider').offcanvas('show');
                        TASK.Ajax.Post(url, data, function(response) {  
                            $('div#rightSlider').find('div.rightSliderContent').html(response);
                            //$('div.offcanvas').offcanvas({canvas: 'body'}); // todo: make it work!
                            console.log('! edit one record form set up');    
                        });

                    }

                });

            //delete    
            $(row).find('td.delete-control').

                attr('data-source', '{{table.form.full_action_url}}?get_delete_form').
                attr('data-canvas', 'body').
                attr('data-target', '#rightSlider').
                attr('data-toggle', 'offcanvas').

                click(function () { 
                    if (!right_offcanvas_visible) {

                        //request form with ajax
                        var url = $(this).attr('data-source');
                        var data = {
                            'choose_record': [record_id]
                        };

                        TASK.Ajax.Post(url, data, function(response) {  
                            $('div#rightSlider').find('div.rightSliderContent').html(response);
                        });

                    }

                });

        {% endif %}


        {% if table.form.rendered_in == 'page' %}
            //on same page above the table

            $(row).find('td.edit-control').
                attr('data-source', '{{table.form.full_action_url}}?get_form').
                click(function () { 
                    console.log('! show edit form above table: '+record_id);    
                    var url = $(this).attr('data-source');
                    var data = {
                        'choose_record': [record_id]
                    };

                    TASK.Ajax.Post(url, data, function(response) {  
                        $('div#form-page-main').html(response);
                        $('html, body').animate({ //scroll smoothly to form
                            scrollTop: $('div#form-page-main').offset().top - config.scrollDistanceFromTop
                        }, config.timeAnimateToAjaxForm);
                    });

                });            


            $(row).find('td.delete-control').
                attr('data-source', '{{table.form.full_action_url}}?get_delete_form').
                click(function () { 
                    console.log('! show delete form above table: '+record_id);    
                    var url = $(this).attr('data-source');
                    var data = {
                        'choose_record': [record_id]
                    };

                    TASK.Ajax.Post(url, data, function(response) {  
                        $('div#form-page-main').html(response);
                        $('html, body').animate({ //scroll smoothly to confirmation
                            scrollTop: $('div#form-page-main').offset().top - config.scrollDistanceFromTop
                        }, config.timeAnimateToAjaxForm);
                    });

                });

        {% endif %}


        {% if table.form.rendered_in == 'modal' %}
            // rendered in modal window

            $(row).find('td.edit-control').
                attr('data-source', '{{table.form.full_action_url}}?get_form').
                attr('data-target', '#largeModal').
                attr('data-toggle', 'modal').
                click(function () { 
                    console.log('! show edit form in modal: '+record_id);    
                    var url = $(this).attr('data-source');
                    var data = {
                        'choose_record': [record_id]
                    };

                    TASK.Ajax.Post(url, data, function(response) {  
                        $('div#largeModal').find('div.modal-body').html(response);
                    });

                });            


            $(row).find('td.delete-control').
                attr('data-source', '{{table.form.full_action_url}}?get_delete_form').
                attr('data-target', '#smallModal').
                attr('data-toggle', 'modal').
                click(function () { 
                    console.log('! show delete form in modal: '+record_id);    
                    var url = $(this).attr('data-source');
                    var data = {
                        'choose_record': [record_id]
                    };

                    TASK.Ajax.Post(url, data, function(response) {  
                        $('div#smallModal').find('div.modal-body').html(response);
                    });

                });

        {% endif %}

Windows (x86、PHP 5.4.19) で Phalcon 1.3.3 TS を使用しています。

どんな提案でも大歓迎です!ありがとう!

4

1 に答える 1

2

ボルト内でphpを起動して、ボルトが提供しないことを行うことができます。

私は将来私たちが持っていると信じています

{% literal %} {% endliteral %} 
or
{% verbatim %} {% endverbatim %}

github にはすでに NFR があります: https://github.com/phalcon/cphalcon/issues/1253

次のように、この部分で純粋なphpを使用するためだけに、方法が見つかりません。

...
<?php
 // your code like it would be simple *.php file
?>
...
于 2014-11-03T22:33:27.000 に答える