Das Kohana Twitter API Modul macht es einem sehr einfach Twitter in seine Applikationen einzubeziehen.
Mit ‘kohana’ getaggte Artikel
kohana twitter api modul
Montag, 14. Juni 2010 von sägefischder Kohana Script Collector Helper
Sonntag, 25. Oktober 2009 von sägefischUm modular und agil in Kohana zu entwickeln, wurde ein Skript Kollektor notwendig, der aus allen Controllern (Template- oder Standard-Controllern) Skripte (CSS, Javascript) sammeln kann.
Diese Scripte werden dann auf den jeweiligen Mastertemplates wieder an den richtigen Stellen eingebunden.
Dazu habe ich einen neuen Helper unter application/helpers/collector.php eingerichtet.
class Collector_Core
{
/**
* Arrays containing URL's to scripts/styles (fill with standards)
* @var string
*/
static protected $scripts = array();
static protected $styles = array();
/**
* Adds a url to store
* @param string $file the local path to file
* @return void
*/
static public function addJs($file)
{
self::$scripts[] = $file;
}
/**
* Adds a url to store
* @param string $file the local path to file
* @return void
*/
static public function addCss($file)
{
self::$styles[] = $file;
}
/**
* Generates/renders collectors items
* @param boolean $print whether to echo the output or just return rendered string
* @return string the rendered output
*/
static public function renderJs($print = false)
{
$scripts = array_unique(self::$scripts);
$output = html::script($scripts);
if ($print)
{
echo $output;
}
else
{
return $output;
}
}
/**
* Generates/renders collectors items
* @param boolean $print whether to echo the output or just return rendered string
* @param string|array $media type for this style (all, screen, print, media)
* @return string the rendered output
*/
static public function renderCss($print = false, $media = 'all')
{
$styles = array_unique(self::$styles);
$output = html::stylesheet($styles, $media);
if ($print)
{
echo $output;
}
else
{
return $output;
}
}
} // end of Collector_Core
Dieser Helper kann nun aus allen Controllern heraus befüllt werden.
class Welcome_Controller extends Template_Controller
{
/**
* set master template
*/
public $template = 'master_default.tpl';
/**
* default constructor
* @param void
* @return void
*/
public function __construct()
{
// load parent constructor
parent::__construct();
// collect scripts and styles
collector::addCss('/css/fancybox');
collector::addJs('/js/jquery.1.3.2');
collector::addJs('/js/jquery.fancybox');
}
/** more code here */
} // end of Welcome_Controller
Nachdem nun alle relevanten Skripte eingesammelt wurden, kann man diese auf dem Template wieder ausgeben lassen.
<?php collector::renderCss(true, 'all'); ?> <!-- html code here --> <?php collector::renderJs(true); ?>
Der Kollektor sorgt dafür das keine doppelten Skripte geladen werden.
SOAP Service mit Kohana und Zend AutoDiscover
Sonntag, 25. Oktober 2009 von sägefischEine einfache all-in-one Lösung für Standard SOAP Services kann man mit dem Kohana Framework und der Zend Bibliothek realisieren.
Dazu bedarf es lediglich eines Kohana Frontcontrollers über den wir den Service und die WSDL ansprechen können.
Zur automatischen Generierung der WSDL, bedienen wir uns hier der Zend AutoDiscover Klasse. Dieser Klasse übergibt man lediglich die ServiceModel-Klasse mit enthaltenen Annotationen, die die Servicefunktionen enthält.
Aus den Annotationen generiert Zend AutoDiscover eine passende WSDL.
/**
* include libs and models
*
*/
include('Zend/Soap/AutoDiscover.php');
include(APPPATH . 'models/service.php');
/**
* this class represents a controller
* application/controllers/soap.php
*
* @package SOAPService
* @subpackage ...
* @author saegefisch (xxx@xxx.xx)
* @copyright (c) 2009 xxx
*/
class Soap_Controller extends Controller
{
/**
* default constructor
*
* @param void
* @return void
*/
public function __construct()
{
// load parent constructor
parent::__construct();
}
/**
* service to call
*
* @param void
* @return void
*/
public function service()
{
// disable wsdl cache
ini_set('soap.wsdl_cache_enabled', '0');
// set auth settings if needed
$settings = array(
'login' => 'user',
'password' => 'password',
'authentication' => SOAP_AUTHENTICATION_BASIC,
'soap_version' => SOAP_1_2,
'encoding' => 'UTF-8',
'cache_wsdl' => WSDL_CACHE_NONE
);
// include user:password if needed
$wsdl = 'http://user:password@' . $_SERVER['HTTP_HOST'] . '/soap/wsdl';
$server = new SoapServer($wsdl, $settings);
$server->setClass('Service_Model');
$server->handle();
}
/**
* wsdl to call
*
* @param void
* @return void
*/
public function wsdl()
{
// disable wsdl cache
ini_set('soap.wsdl_cache_enabled', '0');
$wsdl = new Zend_Soap_AutoDiscover();
$wsdl->setUri('http://' . $_SERVER['HTTP_HOST'] . '/soap/service');
$wsdl->setClass('Service_Model');
$wsdl->handle();
}
}
Hier stellen wir das Standard Model für unseren SOAP Service zusammen.
/**
* this class represents a model
* application/models/service.php
*
* @package SOAPService
* @subpackage ...
* @author saegefisch (xxx@xxx.xx)
* @copyright (c) 2009
*/
class Service_Model extends Model
{
/**
* default constructor
*
* @param void
* @return void
*/
public function __construct()
{
// load database library into $this->db (can be omitted if not required)
parent::__construct();
}
/**
* dummy function
*
* @param int $int
* @param string $string
* @param array $arr
* @param object $obj
* @param bool $bool
* @return array
*/
public function get_dummy_array($int, $string, $arr, $obj, $bool)
{
return array();
}
/**
* dummy function
*
* @param int $int
* @param string $string
* @param array $arr
* @param object $obj
* @param bool $bool
* @return bool
*/
public function get_dummy_boolean($int, $string, $arr, $obj, $bool)
{
return true;
}
/**
* dummy function
*
* @param int $int
* @param string $string
* @param array $arr
* @param object $obj
* @param bool $bool
* @return string
*/
public function get_dummy_string($int, $string, $arr, $obj, $bool)
{
return 'foo=bar';
}
}

















