使用 GET VERB [CakePHP] 调用 view($id) 方法而不是 index() 方法
view($id) Method is being called instead of index() Method with GET VERB [CakePHP]
当我使用 GET VERB 输入 URL http://localhost/cake2/cruds
方法 View() 加载。我想加载 index() 方法...当我使用 GET VERB 输入 URL http://localhost/cake2/cruds/8 时,同样发生。
剩余路线工作正常。
我的路线是:
Router::connect('/', array('[method]'=>'GET','controller' => 'Cruds', 'action' => 'index'));
Router::connect('/', array('[method]'=>'POST','controller' => 'Cruds', 'action' => 'add'));
Router::connect('/:id', array('[method]'=>'GET','controller' => 'Cruds', 'action' => 'view','id'));
Router::connect('/:id', array('[method]'=>'PUT','controller' => 'Cruds', 'action' => 'edit','id'));
Router::connect('/:id', array('[method]'=>'DELETE','controller' => 'Cruds', 'action' => 'delete','id'));
Same Routes 在 CakePHP v3 中运行良好。
我的控制器方法是:
function index()
{
$this->loadModel("crud");
$users = $this->crud->find('all');
//var_dump($users);
$users = Set::extract($users, '{n}.crud');
$this->set('message', json_encode($users,JSON_PRETTY_PRINT));
}`
`function view($id)
{
$this->loadModel("crud");
$user = $this->crud->findById($id);
if (!$user) {
$this->set('message', "User Not Found..!");
}
else
{
$this->set('message',json_encode($user['crud'],JSON_PRETTY_PRINT));
}
}
这一行清楚地表明它将在 id
上调用 view
操作
Router::connect('/:id', array('[method]'=>'GET','controller' => 'Cruds', 'action' => 'view','id'));
所以你想称它为索引所以我们添加了索引而不是视图
Router::connect('/:id', array('[method]'=>'GET','controller' => 'Cruds', 'action' => 'index','id'));
(&我不知道蛋糕php)
当我使用 GET VERB 输入 URL http://localhost/cake2/cruds 方法 View() 加载。我想加载 index() 方法...当我使用 GET VERB 输入 URL http://localhost/cake2/cruds/8 时,同样发生。 剩余路线工作正常。
我的路线是:
Router::connect('/', array('[method]'=>'GET','controller' => 'Cruds', 'action' => 'index'));
Router::connect('/', array('[method]'=>'POST','controller' => 'Cruds', 'action' => 'add'));
Router::connect('/:id', array('[method]'=>'GET','controller' => 'Cruds', 'action' => 'view','id'));
Router::connect('/:id', array('[method]'=>'PUT','controller' => 'Cruds', 'action' => 'edit','id'));
Router::connect('/:id', array('[method]'=>'DELETE','controller' => 'Cruds', 'action' => 'delete','id'));
Same Routes 在 CakePHP v3 中运行良好。 我的控制器方法是:
function index()
{
$this->loadModel("crud");
$users = $this->crud->find('all');
//var_dump($users);
$users = Set::extract($users, '{n}.crud');
$this->set('message', json_encode($users,JSON_PRETTY_PRINT));
}`
`function view($id)
{
$this->loadModel("crud");
$user = $this->crud->findById($id);
if (!$user) {
$this->set('message', "User Not Found..!");
}
else
{
$this->set('message',json_encode($user['crud'],JSON_PRETTY_PRINT));
}
}
这一行清楚地表明它将在 id
view
操作
Router::connect('/:id', array('[method]'=>'GET','controller' => 'Cruds', 'action' => 'view','id'));
所以你想称它为索引所以我们添加了索引而不是视图
Router::connect('/:id', array('[method]'=>'GET','controller' => 'Cruds', 'action' => 'index','id'));
(&我不知道蛋糕php)