Я использую form_helper в CodeIgniter:Codeigniter моя форма помощник
$current = $this->lang->mci_current();
$uri = 'contact';
$url = $this->lang->mci_make_uri($current, $uri); // output "en/contact"
echo form_open($url);
Вопрос:
как изменить form_helper изменить его по умолчанию:
echo form_open('contact');
, но с функциональностью I определенных в предыдущем коде.
Я предполагаю, что я могу создать свою собственную форму помощник (../application/helpers/MY_form_helper.php
) там как изменить его и как использовать свой собственный помощник? Если я префикс помощник с «my_», это означает, что я переопределяю default form_helper? Нужно ли расширять default form_helper?
Это то, что мне удалось сделать:
Примечание: Я новичок в MVC и объектно-ориентированного программирования, обучение с CodeIgniter
Моя попытка:
if (!function_exists('form_open')) {
function form_open($action = '', $attributes = '', $hidden = array()) {
$CI = & get_instance();
$current = $CI->lang->mci_current();
$action = $CI->lang->mci_make_uri($current, $action);
if ($attributes == '') {
$attributes = 'method="post"';
}
// If an action is not a full URL then turn it into one
if ($action && strpos($action, '://') === FALSE) {
$action = $CI->config->site_url($action);
}
// If no action is provided then set to the current url
$action OR $action = $CI->config->site_url($CI->uri->uri_string());
$form = '<form action="' . $action . '"';
$form .= _attributes_to_string($attributes, TRUE);
$form .= '>';
// Add CSRF field if enabled, but leave it out for GET requests and requests to external websites
if ($CI->config->item('csrf_protection') === TRUE AND !(strpos($action, $CI->config->base_url()) === FALSE OR strpos($form, 'method="get"'))) {
$hidden[$CI->security->get_csrf_token_name()] = $CI->security->get_csrf_hash();
}
if (is_array($hidden) AND count($hidden) > 0) {
$form .= sprintf("<div style=\"display:none\">%s</div>", form_hidden($hidden));
}
return $form;
}
}
Так как я предположил, что мой помощник должен быть назван 'MY_form_helper.php', расположенный в' application/helpers/'. Есть ли разница, когда я использую 'my_' вместо' MY_'? –
** Да **, согласно документации, вы должны использовать 'MY_'. http://ellislab.com/codeigniter/user-guide/general/helpers.html –