2013-07-22 64 views
3

我正在使用角js和蛋糕php構建一個簡單的發票模塊。與角JS使用CakePHP表單驗證

使用NG重複領域的項目 - 重複我的觀點所看到如下

<div ng:controller="ItemsCtrl" ng:app> 
<div class="row-fluid items" > 
    <hr> 
    <ul class="invoice_items" ng:init="invoice={items:[{serial:'',details:'',qty:0,unit:'',rate:0,discount:0,amount:0}],pf:0}"> 
    <li ng:repeat="item in invoice.items"> 
    <div class="clear"></div> 
    <div id="items_row"> 
     <div class="field span1"> 
          <?php 
         echo $this->TwitterBootstrap->input("Number", array(
          "input" => $this->Form->text("Item.{{\$index}}.serial" , array('class' => 'serial span1' ,'placeholder' => 'S.No' , 'ng-model' => 'item.serial' , 'value' => '{{ $index + 1 }}' , 'readonly' => 'readonly')) 
         )); ?> 
     </div> 

到底關閉相應的標籤

我在我的模型下面的代碼進行驗證 -

public $validate = array(
    'id' => array(
     'notempty' => array(
      'rule' => array('notempty'), 

     ), 
    ), 
    'serial' => array(
     'notempty' => array(
      'rule' => array('notempty'), 

     ), 
    ), 
    'details' => array(
     'notempty' => array(
      'rule' => array('notempty'), 

     ), 
    ), 
    'quantity' => array(
     'notempty' => array(
      'rule' => array('notempty'), 

     ), 
     'naturalnumber' => array(
      'rule' => array('naturalnumber'), 
      'message' => 'Please enter a valid quantity' 

     ), 
    ), 
    'rate' => array(
     'notempty' => array(
      'rule' => array('notempty'), 

     ), 
     'numeric' => array(
      'rule' => array('numeric'), 

     ), 
    ), 
    'discount' => array(
     'numeric' => array(
      'rule' => array('numeric'), 

     ), 
    ), 
    'amount' => array(
     'notempty' => array(
      'rule' => array('notempty'), 

     ), 
     'numeric' => array(
      'rule' => array('numeric'), 

     ), 
    ), 
); 

問題是ng-repeat指令之外的字段根據需要得到驗證,但是由於內部的字段ng-repeat在每個頁面加載時得到初始化,cakephp驗證不適用於它們。

你們看到這方面的工作嗎?可能我的整個架構方法是錯誤的?

回答

1

我認爲你應該改變你解決問題的方式。

使用CakePHP爲前端創建REST API和AngularJS。它會更容易(如果你想在未來遷移你的堆棧,比如Dart或者NodeJS)更好。

您可能需要閱讀:https://github.com/hantsy/angularjs-cakephp-sample

希望它能幫助。

+0

哦,太糟糕了。沒有檢查問題日期。 – strxfrm