错误404未找到:在此服务器上找不到请求的地址

时间:2016-07-01 06:09:54

标签: php cakephp

我正在尝试从管理面板向数据库添加数据并已创建模型文件,控制器和视图文件夹中有另一个名为neighborhoods文件夹的控制器,其中有两个文件,其名称为index.ctp and add.ctp < / p>

当我尝试访问显示此错误的邻域/索引页面时出现问题

Errors 404 Not Found:The requested address '/admin/neighborhoods/index' 
was not found on this server.

你能告诉我我做错了什么,它的解决方案是什么以及如何访问add.ctp

neighborhood.php模型文件

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

}

neighborhoods_controller文件

class NeighborhoodsController extends AppController
{
    var $name = 'Neighborhoods';

    function beforeFilter()
    {
        $this->Auth->allow('add','index');

    }


     function index() {
        $this->set('Neighborhoods', $this->Neighborhood->find('all'));
    }

    function add() {
        if (!empty($this->data)) {
            if ($this->Neighborhood->save($this->data)) {
                $this->Session->setFlash('Your Neighborhood has been saved.');
                $this->redirect(array('action' => 'index'));
            }
        }
    }

}

1 个答案:

答案 0 :(得分:0)

根据您的网址,您必须为该

创建admin_index()方法
function admin_index() {
        $this->set('Neighborhoods', $this->Neighborhood->find('all'));
    }

试一试。