【发布时间】:2013-12-11 12:42:40
【问题描述】:
我在PostsController部分的cakephp 2.0的博客教程中需要一些帮助
http://book.cakephp.org/2.0/en/tutorials-and-examples/blog/part-two.html
我不明白$id 是从哪里来的,它被定义为$id = null,所以我的理解是$id 应该为空,但它不为空
public function view($id = null) {
if (!$id) {
throw new NotFoundException(__('Invalid post'));
}
$post = $this->Post->findById($id);
if (!$post) {
throw new NotFoundException(__('Invalid post'));
}
$this->set('post', $post);
}
我知道$id 的真正价值来自网址,在本例中为cakephp/posts/view/$id,但我想知道网址中的$id 是如何通过PostsController 获得的
【问题讨论】:
标签: cakephp cakephp-2.0 cakephp-2.3