标签:
(一般在控制器方法中使用)
获取值:
(1)直接获取值:
$customerName = $this->request->getPost("name");
(2)自动添加过滤器:
$email = $this->request->getPost("user_email", "email");
(3)手动添加过滤器:
$filter = new Filter();
$email = $filter->sanitize($this->request->getPost("user_email"), "email");
(4)若值为空,设置默认值
$email = $this->request->getPost("user_email", "email", "some@example.com");
使用请求头信息:
(1)获取服务器IP地址:
$ipAddress = $this->request->getServerAddress();
(2)获取客户端IP地址:
$ipAddress = $this->request->getClientAddress();
文件上传:
use Phalcon\Mvc\Controller;
class PostsController extends Controller
{
public function uploadAction()
{
// Check if the user has uploaded files
if ($this->request->hasFiles()) {
// Print the real file names and sizes
foreach ($this->request->getUploadedFiles() as $file) {
// Print file details
echo $file->getName(), " ", $file->getSize(), "\n";
// Move the file into the application
$file->moveTo(‘files/‘ . $file->getName());
}
}
}
}
标签:
原文地址:http://www.cnblogs.com/wujuntian/p/4695433.html