public function create($model = null, array $options = [])
{
$append = '';
if (empty($options['context'])) {
$options['context'] = [];
}
$options['context']['entity'] = $model;
$context = $this->_getContext($options['context']);
unset($options['context']);
$isCreate = $context->isCreate();
$options += ['type' => $isCreate ? 'post' : 'put', 'action' => null, 'url' => null, 'encoding' => strtolower(Configure::read('App.encoding')), 'templates' => null, 'idPrefix' => null];
if (isset($options['action'])) {
trigger_error('Using key `action` is deprecated, use `url` directly instead.', E_USER_DEPRECATED);
}
if ($options['idPrefix'] !== null) {
$this->_idPrefix = $options['idPrefix'];
}
$templater = $this->templater();
if (!empty($options['templates'])) {
$templater->push();
$method = is_string($options['templates']) ? 'load' : 'add';
$templater->{$method}($options['templates']);
}
unset($options['templates']);
if ($options['action'] === false || $options['url'] === false) {
$url = $this->request->here(false);
$action = null;
} else {
$url = $this->_formUrl($context, $options);
$action = $this->Url->build($url);
}
$this->_lastAction($url);
unset($options['url'], $options['action'], $options['idPrefix']);
$htmlAttributes = [];
switch (strtolower($options['type'])) {
case 'get':
$htmlAttributes['method'] = 'get';
break;
// Set enctype for form
// Set enctype for form
case 'file':
$htmlAttributes['enctype'] = 'multipart/form-data';
$options['type'] = $isCreate ? 'post' : 'put';
// Move on
// Move on
case 'post':
// Move on
// Move on
case 'put':
// Move on
// Move on
case 'delete':
// Set patch method
// Set patch method
case 'patch':
$append .= $this->hidden('_method', ['name' => '_method', 'value' => strtoupper($options['type']), 'secure' => static::SECURE_SKIP]);
// Default to post method
// Default to post method
default:
$htmlAttributes['method'] = 'post';
}
if (isset($options['method'])) {
$htmlAttributes['method'] = strtolower($options['method']);
}
if (isset($options['enctype'])) {
$htmlAttributes['enctype'] = strtolower($options['enctype']);
}
$this->requestType = strtolower($options['type']);
if (!empty($options['encoding'])) {
$htmlAttributes['accept-charset'] = $options['encoding'];
}
unset($options['type'], $options['encoding']);
$htmlAttributes += $options;
$this->fields = [];
if ($this->requestType !== 'get') {
$append .= $this->_csrfField();
}
if (!empty($append)) {
$append = $templater->format('hiddenBlock', ['content' => $append]);
}
$actionAttr = $templater->formatAttributes(['action' => $action, 'escape' => false]);
return $this->formatTemplate('formStart', ['attrs' => $templater->formatAttributes($htmlAttributes) . $actionAttr, 'templateVars' => isset($options['templateVars']) ? $options['templateVars'] : []]) . $append;
}