CakePHP表单不发布数据

时间:2013-05-07 11:26:23

标签: forms cakephp cakephp-1.3

我试图在选项卡中使用CakePHP中的2个表单。

我正在尝试在视图中使用操作'financial_day_begin'。

控制器有2个函数'financial_day'和'financial_bill_day',我在'financial_day_begin'中调用它们。

以下是view的代码,financial_day_begin.ctp:

<div class="panel">
    <h2><?php echo sprintf(__("End of Business %s", true), $financial['Financial']['_end_of_business_date']); ?></h2>
    <div class="panel-content">
        <?php echo $this->element('reports/tabs'); ?>
        <div id="search" class="form">
            <?php
                echo $this->Form->create('Finbill', array('url' => array(
                        'controller' => 'reports',
                        'action' => 'financial_day_begin'
                    )));
                echo $this->Form->input('end_of_bill_date', array(
                    'label' => __("Select Cycle", true),
                    'options' => $finbillList
                ));
                echo $this->Form->end();
            ?>
        </div>
        <?php
            $labels = array(
                'billed_in_cycle'
            );

            echo $this->Html->tag('h3', __("Billed", true));
            echo $this->DataTable->create(array('class' => 'vertical'));

            foreach($labels as $key => $label) {
                if(is_numeric($key)) {
                    $key = $label;
                    $label = Inflector::humanize($label);
                }

                echo $this->DataTable->createRow();
                echo $this->DataTable->createHeader(__($label, true));
                echo $this->DataTable->createCell(sprintf("$%s", number_format($finbill['Finbill'][$key], 2)), array('class' => 'value'));
                echo $this->DataTable->endRow();
            }

            echo $this->DataTable->end();

        ?>
        <div id="search" class="form">
            <?php
                echo $this->Form->create('Financial', array('url' => array(
                        'controller' => 'reports',
                        'action' => 'financial_day_begin'
                    )));
                echo $this->Form->input('end_of_business_date', array(
                    'label' => __("Select Day", true),
                    'options' => $financialList
                ));
                echo $this->Form->end();
            ?>
        </div>
        <?php
            $labels = array(
                'billed_adjustments' => 'Adjustments'
            );

            echo $this->Html->tag('h3', __("Adjustments", true));
            echo $this->DataTable->create(array('class' => 'vertical'));

            foreach($labels as $key => $label) {
                if(is_numeric($key)) {
                    $key = $label;
                    $label = Inflector::humanize($label);
                }

                echo $this->DataTable->createRow();
                echo $this->DataTable->createHeader(__($label, true));
                echo $this->DataTable->createCell(sprintf("$%s", number_format($financial['Financial'][$key], 2)), array('class' => 'value'));
                echo $this->DataTable->endRow();
            }

            echo $this->DataTable->end();

            $labels = array(
                'payments',
                'payment_reversals',
                'payments_net' => 'Net Payments'
            );

            echo $this->Html->tag('h3', __("Payments", true));
            echo $this->DataTable->create(array('class' => 'vertical'));

            foreach($labels as $key => $label) {
                if(is_numeric($key)) {
                    $key = $label;
                    $label = Inflector::humanize($label);
                }

                echo $this->DataTable->createRow();
                echo $this->DataTable->createHeader(__($label, true));
                echo $this->DataTable->createCell(sprintf("$%s", number_format($financial['Financial'][$key], 2)), array('class' => 'value'));
                echo $this->DataTable->endRow();
            }

            echo $this->DataTable->end();
        ?>
    </div>
</div>
<?php
    $this->Html->script("reports/financial_day", array('inline' => false));
?>

这是我的控制器,reports_controller.php:

<?php
    class ReportsController extends AppController {

        var $name = 'Reports';
        var $uses = array(
            'Subscriber',
            'Financial',
            'Finbill',
            'Trend'
        );

        var $presetVars = array(
            array(
                'field' => 'posted',
                'type' => 'value'
            ),
            array(
                'field' => 'end_of_business_date',
                'type' => 'value'
            ),
            array(
                'field' => 'end_of_bill_date',
                'type' => 'value'
            ),
            array(
                'field' => 'start_id',
                'type' => 'value'
            ),
            array(
                'field' => 'end_id',
                'type' => 'value'
            ),
            array(
                'field' => 'month_year',
                'type' => 'value'
            )
        );

        function index() {
            $subscriber = $this->Subscriber->find('first', array(
                'contain' => false,
                'order' => array('posted' => 'desc')
            ));

            $this->set(compact('subscriber'));
        }

        function financial_bill_day() {
            $this->Prg->commonProcess('Finbill');

            $searchConditions = $this->Finbill->parseCriteria($this->passedArgs);

            $finbill = $this->Finbill->find('first', array(
                'conditions' => $searchConditions,
                'contain' => false,
                'order' => array('end_of_bill_date' => 'desc')
            ));

            $finbillList = $this->Finbill->find('list', array(
                'contain' => false,
                'fields' => array(
                    'end_of_bill_date'
                ),
                'order' => array('end_of_bill_date' => 'desc')
            ));

            $this->set(compact('finbill', 'finbillList'));
        }

        function financial_day() {
            $this->Prg->commonProcess('Financial');

            $searchConditions = $this->Financial->parseCriteria($this->passedArgs);
            $financial = $this->Financial->find('first', array(
                'conditions' => $searchConditions,
                'contain' => false,
                'order' => array('end_of_business_date' => 'desc')
            ));

            $financialList = $this->Financial->find('list', array(
                'contain' => false,
                'fields' => array(
                    'end_of_business_date',
                    '_end_of_business_date'
                ),
                'order' => array('end_of_business_date' => 'desc')
            ));

            $this->set(compact('financial','financialList'));
        }

        function financial_day_begin() {
            $this->financial_day();

            $this->financial_bill_day();

            $this->set(compact('finbill','finbillList','financial','financialList'));
        }

    }
?>

问题是,当我尝试从我的选择框中的下拉列表中选择输入值时,没有发布任何内容(根据浏览器中的地址栏)。我猜这就是为什么不调用新值。

在ctp文件之外是否有一些我们需要定义应该调用的操作的地方?

非常感谢任何有关此问题的帮助。

1 个答案:

答案 0 :(得分:2)

这些表单将提交发布请求,而不是获取请求,因此数据不会在URL中。如果要查看正在提交的数据,请尝试在控制器操作开始时添加debug($this->data)$this->passedArgs也应该被$this->data替换。如果您希望表单使用get请求,您应该更改它们:

echo $this->Form->create('Finbill', array(
    'url' => array(
        'controller' => 'reports',
        'action' => 'financial_day_begin'
    ),
    'type' => 'get'
));
相关问题