0

私はCakePHPを初めて使用し、それを学んでいます.save()でデータを挿入しましたが、MySQLデータベースからデータを更新または削除する方法がわかりません. 私は非常に多くのことを見つけたので、これらは私には理解できません..誰か助けてもらえますか...

私のordersControllerは-

    class OrdersController extends AppController
    {
var $name = 'Orders';
var $helpers = array('Html', 'Form');
//var $ords = array('id', 'order_no' );

     public function order()
    { 
      $this->set('orders', $this->Order->find('all')); 

    }

    public function add_order()
    { 
                if (!empty($this->data)) {

                if ($this->Order->save($this->data)) {

                $this->redirect('/');
                }

                }
         }


      public function edit()
     { 

///// これは表示されている私のページ名です。ここで何をすべきか..????

       }

///私のモデルの注文は --

      App::uses('Model', 'Model');

     class Order extends AppModel 
      {
   var  $name = 'Order';

       }

// ビュー内の edit.php で何をすべきかわかりません ...

前もって感謝します

4

1 に答える 1

0

ビューフォルダーにファイル edit.ctp を作成するだけです

add.ctp と同じ

次に、コントローラーに編集機能を作成します

public function edit($id = null){ }

今、あなたの index.ctp から、この edit.ctp へのリンクを次のように与えます

 eg.
 <?php echo $this->Html->link(__('Edit'), array('action' => 'edit', $order['Order']['Id'])); ?>

あなたの目的を解決します。

こんにちは、このコントローラー機能を試してください

public function edit($id = null) {

    if (!$this->Order->exists()) {
        throw new NotFoundException(__('Invalid order'));
    }
    if ($this->request->is('post') || $this->request->is('put')) {          

                if ($this->Order->save($this->request->data)) {
            $this->Session->setFlash(__('Your order has been Modified Sucessfully'));
            $this->redirect(array('action' => 'index'));
        } else {
            $this->Session->setFlash(__('Your order not been Modified Sucessfully.'));
        }
    } 

            else {
        $this->request->data = $this->Order->read(null, $id);
         }

}   
于 2013-09-30T08:43:58.453 に答える