2013-05-07 84 views
0

我想在一个选项卡中使用CakePHP中的2个表单。CakePHP表单不发布数据

我想在视图中使用操作'financial_day_begin'。

控制器有两个函数'financial_day'和'financial_bill_day',我都在'financial_day_begin'中调用这两个函数。

以下是视图的代码,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文件之外是否有一些地方需要定义应该调用的动作?

对这个问题的任何帮助是非常感谢。

回答

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' 
)); 
+0

基本上,我想说,在我看来,有2种形式,调用同样的动作。从应用程序,只有当我改变我的选择在第二种形式,行动(函数financial_day_begin)被调用。以第一种形式更改选择不会调用该操作。我在这里做错了什么?我也尝试过使用不同的函数名称,但第一种形式的动作并没有被调用。 – user2358060 2013-05-14 06:54:19