PHP Cakephp添加了功能

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP Cakephp添加了功能相关的知识,希望对你有一定的参考价值。

function addedit($id = null) {
	if (empty($this->data)) {
		if($id) {
			// Edit data, populate fields
			$this->data = $this->Model->read(null, $id);			
		} else {
			// Create, prefill some fields..
			$the_user = $this->Auth->user();
			$this->data['Model']['user_id'] = $the_user['User']['id'];
		}
	} else {
		if($id == null) {
			// Create model
			$this->Model->create();
		}
		if ($this->Article->save($this->data)) {
			$this->Session->setFlash(__('The Article has been saved', true));
			
			// Add this to form: 
			// echo $form->submit(__('Save and close', true), array('name'=>'close'));
			if(isset($this->params['form']['close'])) {
				$this->redirect(array('action'=>'index'));
			}
			if($id == null) {
				$new_id = $this->Model->getInsertID();
				$this->redirect(array('action'=>'addedit', $new_id));
			}
			$this->data = $this->Model->read(null, $id);	
		} else {
			$this->Session->setFlash(__('The Model could not be saved. Please, try again.', true));
		}
	}
}

以上是关于PHP Cakephp添加了功能的主要内容,如果未能解决你的问题,请参考以下文章

CAKEPHP 3 和 Dompdf - 缺少 Cpdf.php 类

CakePHP 创建新页面

cakephp 2.0 中的忘记密码功能

如何为现有的 CakePHP (2) 项目添加新的 url 路由

CakePHP 2.1 JsonView

不能用cakePHP html helper添加css版本控制