0

ヘッダー付きのデフォルト レイアウト (default.ctp) があります。このヘッダーには、次のコードで各ページに表示される検索フォームがあります。

echo $this->Form->create('null', array('url' => '/search/result'),array(
                        'inputDefaults' => array(
                            'label' => false,
                            'div' => false
                        )
                    ));

                    echo $this->Form->input('search_query', array('label' => false, 'div' => false, 'type' => 'tel','class' => 'input-small', 'id' => 'appendedInputButton', 'placeholder' => 'Input search'));

                    echo $this->Form->button('Search', array('class' => 'btn'));
                    echo $this->Form->end()

この default.ctp ファイルでは、次の行で twitterbootstrap 入力モーダル オーバーレイを呼び出します。この要素はすべてのページで使用されます。

<!-- Add order modal -->
        <?php echo $this->element('add_customer_order');?>

この要素では、bestelling/modal_ext に対して request アクションを実行して、フォーム検証が使用され、フォームフィールドが正しい方法でセットアップされ、bestelling コントローラーで保存できるようにします。次のコードは要素にあります。

<?php    
$this->requestAction('Bestelling/modal_ext');//Include BestellingController modal_ext               
?>
<!-- Add order modal -->
        <div id="Bestellingtoevoegen" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            <h3 id="myModalLabel">Add customer order</h3>
            </div>
            <div class="modal-body">

                    <div class="row-fluid">
                        <div class="span8"> 
                            <?php
                            echo $this->Form->create('Bestelling');
                            //echo $this->Form->create('null', array('url' => '/bestelling/modal_ext'));
                            echo $this->Form->input('bestelnummer', array('type' => 'tel','class' => 'input-small'));
                            echo $this->Form->input('klantnummer', array('type' => 'tel','class' => 'input-small')); ?>
                        </div>
                        <div class="span4">
                            <br/>
                            <?php echo $this->Form->checkbox('serial'); echo' <span class="label label-info">Serialcode</span> '; ?>
                            <br/>
                            <?php echo $this->Form->checkbox('insured'); echo' <span class="label label-info">Insured</span>'; ?>
                            <br/>
                            <?php echo $this->Form->checkbox('giftpaper'); echo' <span class="label label-info">Giftpaper</span>'; ?>
                        </div>
                    </div>

                    <div class="row-fluid">
                        <div class="span5"> 

                            <?php 
                            echo $this->Form->input('titel', array('type' => 'tel', 'id' => 'discription', 'onkeyup' => 'lookupproductnamenew(this.value);', 'onblur' => 'fill();', 'after' => '<div class="suggestionsBox" id="suggestions" style="display: none;">
                                    <img src="images/upArrow.png" style="position: relative; top: -20px; left: 30px;" alt="upArrow" />
                                    <div class="suggestionList" id="autoSuggestionsList">
                                    </div>
                            </div>'));
                            ?>
                        </div>

                        <div class="span7">
                            <?php
                            echo $this->Form->input('aantal', array(
                                'options' => array(
                                '1' => '1',
                                '2' => '2',
                                '3' => '3',
                                '4' => '4',
                                '5' => '5',
                                '6' => '6',
                                '7' => '7',
                                '8' => '8',
                                '9' => '9',
                                '10' => '10',
                                '11' => '11',
                                '12' => '12'),

                                'div' => 'input-prepend',
                                'label' => '&nbsp;',
                                'between' => '<span class="add-on">X</span>',
                                'class' => 'span8',
                                'id' => 'prependedInput',

                            ));
                            ?>
                       </div>
                   </div>

                   <div class="row-fluid">  
                        <div class="span12">
                        <?php
                        echo $this->Form->input('opmerking', array('type' => 'textarea', 'class' => 'span10','rows' => '4', 'cols' => '90'));
                        ?>
                        </div>
                   </div>     
            </div>
                        <?php 
                        echo $this->Form->hidden('levertijd', array('type' => 'tel', 'id' => 'levertijd', 'onblur' => 'fill();'));
                        echo $this->Form->hidden('prijs', array('type' => 'tel', 'id' => 'prijs', 'onblur' => 'fill();'));
                        echo $this->Form->hidden('artikelnummer', array('type' => 'tel', 'id' => 'artikelnummer', 'onblur' => 'fill();'));
                        echo $this->Form->hidden('ean', array('type' => 'tel', 'id' => 'ean', 'onblur' => 'fill();'));
                        echo $this->Form->hidden('overtime', array('type' => 'tel', 'id' => 'overtime', 'onblur' => 'fill();'));
                        echo $this->Form->hidden('productgroep', array('type' => 'tel', 'id' => 'productgroep', 'onblur' => 'fill();'));
                        ?>

            <div class="modal-footer">
            <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
            <?php
            echo $this->Form->button('Save', array('class' => 'btn btn-primary'));echo'<br/>';
            echo $this->Form->end();
             ?>
            </div>
        </div>                


<!-- End Add order modal -->

ヘッダーにフォームを送信すると、フォームから /search/result に送信され、データが送信されたことを確認できますが、bestellingcontroller が呼び出されたというエラーも表示されます。したがって、ヘッダーでフォームを送信すると、他のフォームも送信されます。

要素の request アクションを削除し、 Form => create を次のように置き換えると:

echo $this->Form->create('null', array('url' => '/bestelling/modal_ext'));

それは正常に動作しますが、値が [Bestelling][fieldname] のような配列ではないため、このフォームの検証が失われ、$request->data が変更されます。配列の構造の変更は大きな問題ではありませんが、正しい方法で行いたいと考えています。誰かがこの問題を解決するために正しい方向に私を助けることができます. 私は CakePHP に非常に慣れていませんが、アクションを呼び出す方法が私のプログラムによって正しく行われていないと思います。

4

2 に答える 2

0

読みやすくするために、オランダ語の命名は英語に置き換えられました

私は問題を見つけましたが、実際にはこのエラーを引き起こす非常に小さなエラーでした (私は思います)。このエラーは、データベース テーブルの順序の命名が原因でした。Cakephp は、データベーステーブルが余分な S で注文と呼ばれていると想定していましたが、そうではなかったので、データベースを次のように設定していました

 $this->Order->setSource('order');

名前を今すぐ注文に変更し、add_customer_order の次の行を削除しました

$this->requestAction('Order/modal_ext');//Include OrderController modal_ext

私はまだdefault.ctpで次の行を使用しています

echo $this->Form->create('null', array('url' => '/search/result'),array(

しかし、これは今のところ何の問題もありません。このコントローラーは、コントローラーの setSource によって設定されたテーブル orders を検索します。null を Search に変更すると、データベース テーブルの検索が存在しないため、エラーが発生します。null を置き換えることができるように、正しい方法でそれを行う場合、このフォームはコントローラーの順序を指す必要があります。期待どおり、両方のフォームが別々に送信されるようになりました。全体の問題は、cakephp の命名規則に従っていなかったことにあると思います。おそらく、この命名規則に再び遭遇し、それに従うのがより簡単になります(テーブルの名前を変更します)。

于 2013-05-13T22:02:05.457 に答える