【发布时间】:2015-08-01 12:23:48
【问题描述】:
我是 cakePHP 的新手,尝试创建一个博客站点,用户在选择类别后添加博客,我有一个类别表:字段:category_id、名称和帖子表:字段:id、category_id、标题、正文。 我想将所有类别提取到下拉列表中。当用户添加新帖子时,他们必须先选择类别,然后他才能发布任何内容..
我的帖子控制器:
<?php
class PostsController extends AppController{
public $helpers = array('Html', 'Form', 'Session');
public $components = array('Session','Paginator');
public function index(){
$this->Paginator->setting = array(
'limit' =>'10',
'order' => array('Post.id' =>'Desc')
/*'conditions' => array(
'Post.user_id' => AuthComponent::user(id)
)*/
);
$arrPosts = $this->Paginator->paginate('Post');
$this->set('posts', $arrPosts);
}
public function view($id = null){
if(!$id){
throw new NotFoundException(__("Error Processing Request ID"));
}
$post =$this->Post->findById($id);
if(!$post){
throw new NotFoundException(__("Error Processing Request POST"));
}
$this->set('post',$post);
}
public function add(){
// HERE I want to fetch all categoryies from categories table and want to send to view
if($this->request->is('post')){
$this->Post->create();
if($this->Post->save($this->request->data)){
$this->Session->setFlash(__('Blog Posted Sucessfully'));
return $this->redirect(array('action' => 'index'));
}else{
$this->Session->setFlash(__('Unable to Post Blog '));
}
}
}
}
?>
我想以添加形式显示我的类别:
请帮帮我...
【问题讨论】:
标签: php mysql cakephp cakephp-2.0