我想从Controller中的数据库获取id,然后使用其名称创建具有该名称的目录。
public function album($id = null) {
$dirname = $this->Dog->query('SELECT * from dogs WHERE id='$id'');
$dir = new Folder(WWW_ROOT . 'albums' . DS . 'files' . DS . $dirname->name , true, 0755);
$this->layout = 'edit';
if (!$id) {
throw new NotFoundException(__('Zły post'));
}
$Dog = $this->Dog->findById($id);
if (!$Dog) {
throw new NotFoundException(__('Zły post'));
}
if ($this->request->is('post') || $this->request->is('put')) {
$this->Dog->id = $id;
if ($this->Dog->save($this->request->data)) {
$this->Session->setFlash(__('Edycja zakończona sukcesem.'));
$this->redirect(array('action' => 'index_psy'));
} else {
$this->Session->setFlash(__('Spróbuj ponownie.'));
}
}
}
我尝试过其他一些解决方案,但似乎都没有。 谢谢你的帮助
答案 0 :(得分:2)
public function album($id) {
//if id doesn't exist Exit
if (!$this->Dog->exists($id)) {
throw new NotFoundException(__('Invalid album'));
}
$dog = $this->Dog->findById($id);
//create a folder with directory name
$path = 'files' . DS . $dog['Dog']['name'];
$folder = new Folder($path , true, 0755);
$this->layout = 'edit';
}
}
look at here 只是为了得到一个想法