Helpers are handy features that are designed to help you with development.
They are similar to library functions, but there is a slight difference. In the case of libraries, it is necessary to create an instance of the library class in order to use its methods. Helpers are static class methods that are automatically loaded by the framework, so there is no need to perform additional actions.
<?php class Helper_MyUrl { public static function SEOIt($str) { $str = preg_replace(array('/\s/', '/[$.+!*\'(),"]/'), array('-', ""), $str); return $str; } }
<br /><?php echo Helper_MyUrl::SEOIt('This Is a string!!!');?>
modules +-- fortune |-- classes | +-- kohana +-- views +-- fortune
<?php defined('SYSPATH') or die('No direct script access.'); class Fortune extends Kohana_Fortune{}
<?php defined('SYSPATH') or die('No direct script access.'); /** * Fortune Cookie Module */ class Kohana_Fortune { // Merged configuration settings protected $config = array('view' => 'fortune/default'); protected $fortune = ""; /** * Creates a new Fortune object. * * @return Fortune */ public static function factory(array $config = array()) { return new Fortune($config); } public function __construct(array $config = array()) { // Overwrite system defaults with application defaults $this->config = $this->config_group() + $this->config; } /** * Retrieves a fortune config group from the config file. One config group can * refer to another as its parent, which will be recursively loaded. * * @param STRING fortune config group; "default" if none given * @return ARRAY config settings */ public function config_group($group = 'default') { // Load the fortune config file $config_file = Kohana::config('fortune'); // Initialize the $config array $config = array('group' => (string)$group); // Recursively load requested config groups while(isset($config['group']) && isset($config_file->$config['group'])) { // Temporarily store config group name $group = $config['group']; unset($config['group']); // Add config group values, not overwriting existing keys $config += $config_file->$group; } // Get rid of possible stray config group names unset($config['group']); // Return the merged config group settings return $config; } /** * Randomly pick a fortune * * @return STRING fortune text */ public function getFortune() { // Stolen from: http://fortunes.cat-v.org/plan_9/ $fortunes = array('2 is always smaller than 3, even for large values of 2.', 'A penny saved is a political breakthrough.', 'Avoid reality at all costs.', 'Bad taste is timeless.'); $this->fortune = $fortunes[array_rand($fortunes, 1)]; } /** * Renders the fortune. * * @param MIXED string of the view to use, or a View object * @return STRING fortune output (HTML) */ public function render($view = NULL) { if($view === NULL) { // Use the view from config $view = $this->config['view']; } if(!$view instanceof View) { // Load the view file $view = View::factory($view); } $this->getFortune(); // Pass on the whole Fortune object return $view->set(get_object_vars($this))->set('page', $this)->render(); } /** * Renders the fortune. * * @return STRING fortune output (HTML) */ public function __toString() { return $this->render(); } }
<div style="width: 250px; height: 52px; vertical-align: middle; display: table-cell; text-align: center; border: 1px solid #CCCCCC; border-right-color: #666666; border-bottom-color: #666666;"> <p><?php echo $fortune;?></p> </div>
Kohana::modules(array(// 'auth' => MODPATH.'auth', // Basic authentication // 'codebench' => MODPATH.'codebench', // Benchmarking tool 'database' => MODPATH.'database', // Database access // 'image' => MODPATH.'image', // Image manipulation // 'orm' => MODPATH.'orm', // Object Relationship Mapping // 'pagination' => MODPATH.'pagination', // Paging of results // 'userguide' => MODPATH.'userguide', // User guide and API documentation 'fortune' => MODPATH.'fortune', ));
<?php echo Fortune::factory();?>
$path = Kohana::find_file('vendors', 'Zend/Loader'); if($path) { ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . dirname(dirname($path))); require_once 'Zend/Loader/Autoloader.php'; Zend_Loader_Autoloader::getInstance(); }
<?php $validator = new Zend_Validate_Isbn();?> <br />978-3-16-148410-0 <?php echo ($validator->isValid('978-3-16-148410-0')) ? 'is' : 'is not';?> valid. <br />9783161484100 <?php echo ($validator->isValid('9783161484100')) ? 'is' : 'is not';?> valid.
Source: https://habr.com/ru/post/112338/
All Articles