PHP 扩展的Kohana HTML助手

Posted

tags:

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

<?php defined('SYSPATH') or die('No direct script access.');
 
class html extends html_Core {
	
	public static function lianchor(array $links, $curr_check = NULL, $li_active_class = NULL, $a_active_class = NULL)
	{
		$output = null;
		foreach($links as $link => $name)
		{
			$li_class = null;
			$a_class = null;
			
			if($link == $curr_check)
			{
				if($li_active_class != NULL)
					$li_class = array('class' => $li_active_class);
				if($a_active_class != NULL)
					$a_class = array('class' => $a_active_class);
			}
			
			$output .= '<li'.parent::attributes($li_class).'>'.parent::anchor($link, $name, $a_class).'</li>'."\n";
		}
		
		return $output;
	}
	
	public static function script($script, $index = FALSE)
	{
		$compiled = '';

		if (is_array($script))
		{
			foreach ($script as $name)
			{
				$compiled .= html::script($name, $index);
			}
		}
		else
		{
			if (strpos($script, '://') === FALSE)
			{
				// Add the suffix only when it's not already present
				$script = url::base((bool) $index).$script;
			}

			if (substr_compare($script, '.js', -3, 3, FALSE) !== 0 && substr_compare($script, '/', -1, 1, FALSE) !== 0)
			{
				// Add the javascript suffix
				$script .= '.js';
			}

			$compiled = '<script type="text/javascript" src="'.$script.'"></script>';
		}

		return $compiled."\n";
	}
	
	public static function image($src = NULL, $alt = NULL, $index = FALSE)
	{
		// Create attribute list
		$attributes = is_array($src) ? $src : array('src' => $src);

		if (is_array($alt))
		{
			$attributes += $alt;
		}
		elseif ( ! empty($alt))
		{
			// Add alt to attributes
			$attributes['alt'] = $alt;
		}
		else
		{
			$attributes['alt'] = '';
		}

		if (strpos($attributes['src'], '://') === FALSE)
		{
			// Make the src attribute into an absolute URL
			$attributes['src'] = url::base($index).$attributes['src'];
		}

		return '<img'.html::attributes($attributes).' />';
	}
}

以上是关于PHP 扩展的Kohana HTML助手的主要内容,如果未能解决你的问题,请参考以下文章

zend-framework 与 Kohana 与 Symfony [关闭]

搜索 Kohana 初学者的 PHP 教程 [关闭]

Kohana查询字符串URL扩展

kohana orm巧用字段备注支持扩展

PHP 获取当前在Kohana 3的路线

Kohana3 ORM 需要澄清关系