2

コントローラーに次のコードがあります。

class ContactsController extends AppController {
    public $helpers = array('Html', 'Form', 'Session');
    public $components = array('Session');

    public function index() {
        $this->set('contacts', $this->Contact->find('all'));
    }

    public function view($id) {
        if (!$id) {
            throw new NotFoundException(__('Invalid contact'));
        }

        $contact = $this->Contact->findById($id);
        if (!$contact) {
            throw new NotFoundException(__('Invalid contact'));
        }
        $this->set('contact', $contact);
    }

    public function add() {                 
        if ($this->request->is('post')) {
            $this->Contact->create();
            if ($this->Contact->save($this->request->data)) {
                $this->Session->setFlash('Your contact has been saved.');
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash('Unable to add your contact.');
            }
        }
    }
}

add() メソッドには、$this->redirect(array('action' => 'index'));この行がビュー内のインデックス ページにリダイレクトされることを期待している行があります。しかし、私が得るのは空白の白いページだけです。

どんな助けでも感謝します。

よろしく、スティーブン

4

2 に答える 2

6

多くの研究の後、最終的に私はそれに対する解決策を得ました。

使ってください

ob_start();AppController.php

ob_start();
class AppController extends Controller {
     function beforeFilter() {
         parent::beforeFilter();
     }
}
于 2015-08-17T05:03:29.950 に答える