在我的项目中使用Phalcon的Volt引擎时,我遇到了奇怪的PHP错误。这个案例看起来很简单但是虽然我多次检查过我的代码,但我似乎无法使用简单的if-elseif-endif结构。
模板代码在这里,它放在jQuery块中,在jQuery callcack函数的上下文中:
{% 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编译器在下面引用的第一个参考文件中生成的,伏特文件没有编译成PHP。
{% elseif table.form.rendered_in == 'page' %}
错误说: 第307行的/ app / views / partials / grideditor.volt中的意外ENDIF
if-elseif-endif结构在Javascript块的其他地方运行良好。更让人感到奇怪的是,当我用多个if-endif替换elseif时,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上使用Phalcon 1.3.3 TS(x86,PHP 5.4.19)
非常感谢任何建议!谢谢!
答案 0 :(得分: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
?>
...