Небольшая заметка, о том как добавить в хелпер html, возможность вывода favicon-а
Я не нашел, в стандартной поставке, хелпера для вывода favicon-а, поэтому определил свой.
Для этого, копируем файлик-заготовку из системной папки:
kohana-root/system/classes/html.php
в папку с приложением
kohana-root/application/classes/html.php
теперь добавляем туда такой метод
<?php defined('SYSPATH') or die('No direct script access.'); class HTML extends Kohana_HTML { /** * Creates a link element. * * echo HTML::link('media/img/favicon.ico', array('rel'=>'ico', 'type'=>'image/x-icon')); * * @param string file name * @param array default attributes * @param mixed protocol to pass to URL::base() * @param boolean include the index page * @return string * @uses URL::base * @uses HTML::attributes */ public static function link($file, array $attributes = NULL, $protocol = NULL, $index = FALSE) { if (strpos($file, '://') === FALSE) { // Add the base URL $file = URL::base($protocol, $index).$file; } // Set the stylesheet link $attributes['href'] = $file; return '<link'.HTML::attributes($attributes).' />'; } }
на этом модификация хелпера закончена, теперь можем добавить в вид, в секцию header-а, такой код:
<?=html::link('media/img/favicon.ico', array('rel'=>'ico', 'type'=>'image/x-icon'))?> <?=html::link('media/img/favicon.ico', array('rel'=>'shortcut icon', 'type'=>'image/x-icon'))?>
где media/img/favicon.ico = путь к вашей иконке, относительно http пути сайта.
Комментарии (6)
Добрый день. Прошу прощения за свое невежество, вообще ничего не понимаю в кохана, но по работе нужно отредактировать в старом сайте, который кто-то когда-то написал на кохана. мне нужно вставить фавикон, но ничего не выходит. первую часть вашей подсказки могу выполнить, но вот что такое секция хедера не понимаю?
Привет, "в секцию header", имеется ввиду что нужно найти файл шаблона и там вставить этот код между тэгами
<head>...</head>
. Файлы шаблона находятся тут: application/views/*.php , всего скорее основной файл должен называться что-то вроде: index.php, base.php, layout.php или header.php. Если там таких файлов нет, тогда поищи текст<head>
в этой папке по всем файламблагодарю
спасибо, помогло
в комментарие обрезанны некоторые символы...
находим файл
/locserver/kohana.seo_admin.rom/run/system/classes/kohana/html.php
..
далее находим "public static function style(..."
...
далее меняем строки:
$attributes['rel'] = 'stylesheet';
на
$attributes['rel'] = arr::get($attributes, ‘rel’, ‘stylesheet’);
;;;
$attributes['type'] = 'text/css';
на
$attributes['type'] = arr::get($attributes, ‘type’, ‘text/css’);
предлагаю такую модификацию:
public static function style($file, array $attributes = NULL, $protocol = NULL, $index = FALSE)
{
if (strpos($file, '://') === FALSE)
{
// Add the base URL
$file = URL::base($protocol, $index).$file;
}
// Set the stylesheet link
$attributes['href'] = $file;
// Set the stylesheet rel
$attributes['rel'] = arr::get($attributes, 'rel', 'stylesheet');
// Set the stylesheet type
$attributes['type'] = arr::get($attributes, 'type', 'text/css');
return '';
}
****
если кратко, нужно заменить 2-е строки:
$attributes['rel'] = arr::get($attributes, 'rel', 'stylesheet');
$attributes['type'] = arr::get($attributes, 'type', 'text/css');