我是CakePHP初學者,我想我必須缺少一些基本的基本知識。我想要做的是在我的View文件中有一個鏈接,點擊時會導致Model方法的執行。我試圖用CakePHP博客教程作爲起點。嘗試從CakePHP中的Controller調用Model方法時出現「Missing View」錯誤
我的視圖文件(網站/ view.ctp)包括以下幾個環節:
<tr><td class="label">Actions</td><td><?php echo $this->Form->postLink('Sync Pages', array('action' => 'sync', $site['Site']['id']), array('confirm' => 'Are you sure you want to try that?')); ?> | <?php echo $this->Html->link('Edit', array('action' => 'edit', $site['Site']['id'])); ?></td></tr>
我的控制文件(SitesController.php)包括以下功能:
// Delete function copied from the Cake tutorial
public function delete($id) {
if ($this->request->is('get')) {
throw new MethodNotAllowedException();
}
if ($this->Site->delete($id)) {
$this->Session->setFlash(__('The site with id: %s has been deleted.', h($id)));
return $this->redirect(array('action' => 'index'));
}
}
// My failing function (results in "Missing View" error)
public function sync($id) {
if ($this->request->is('get')) {
throw new MethodNotAllowedException();
}
if ($this->Site->syncPages($id)) {
$this->Session->setFlash(__('The site with id: %s has been synced.', h($id)));
return $this->redirect(array('action' => 'view', $id));
}
}
我的模型文件(Site.php)包括以下功能草稿:
public function syncPages() {
$cms = $this->cms;
if ($this->cms == 'Wordpress')
{
// ... do stuff to retrieve data from a remote Wordpress database and save it to the local CakePHP app database
}
}
但是,如上所述,abo ve,我無法獲得syncPages()函數來執行。當我點擊Sync鏈接時,出現「Missing View」錯誤。我哪裏錯了?在此先感謝您的幫助!
對於那些來自搜索的人:在我的例子中'beforeFilter()'引發了這個問題。有關更多信息,請參閱http://stackoverflow.com/questions/16921021/cakephp-plugin-throws-missing-view-error-but-view-file-exits/40872968#40872968。 –