<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>NinjaCipher &#187; php</title>
	<atom:link href="http://www.ninjacipher.com/category/development/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ninjacipher.com</link>
	<description>kungpow programming</description>
	<lastBuildDate>Thu, 25 Mar 2010 14:39:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='www.ninjacipher.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>smarty ternary modifier plug-in</title>
		<link>http://www.ninjacipher.com/2007/11/24/smarty-ternary-modifier/</link>
		<comments>http://www.ninjacipher.com/2007/11/24/smarty-ternary-modifier/#comments</comments>
		<pubDate>Sun, 25 Nov 2007 06:06:04 +0000</pubDate>
		<dc:creator>mattd</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tutorials]]></category>

		<guid isPermaLink="false">http://www.ninjacipher.com/2007/11/24/smarty-ternary-modifier/</guid>
		<description><![CDATA[Here is a modifier plug-in that I wrote for smarty that does a simple ternary operation. I would have thought that they would have this built in but from my searches it doesn&#8217;t seem to be the case.

function smarty_modifier_ternary($value,$option1,$option2)
{
    return ($value)?$option1:$option2;
}
You can use it like so&#8230;

{$post.is_draft&#124;ternary:'draft':'published'}
If you don&#8217;t know how to use [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a modifier plug-in that I wrote for smarty that does a simple ternary operation. I would have thought that they would have this built in but from my searches it doesn&#8217;t seem to be the case.</p>
<pre>
function smarty_modifier_ternary($value,$option1,$option2)
{
    return ($value)?$option1:$option2;
}</pre>
<p>You can use it like so&#8230;</p>
<pre>
{$post.is_draft|ternary:'draft':'published'}</pre>
<p>If you don&#8217;t know how to use smarty plug-ins then you can <a href="http://smarty.php.net/manual/en/plugins.php" target="new">read up here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ninjacipher.com/2007/11/24/smarty-ternary-modifier/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>View helpers with Zend Framework</title>
		<link>http://www.ninjacipher.com/2007/11/14/view-helpers-in-zend-framework/</link>
		<comments>http://www.ninjacipher.com/2007/11/14/view-helpers-in-zend-framework/#comments</comments>
		<pubDate>Thu, 15 Nov 2007 05:06:02 +0000</pubDate>
		<dc:creator>mattd</dc:creator>
				<category><![CDATA[zend framework]]></category>

		<guid isPermaLink="false">http://www.ninjacipher.com/2007/11/14/view-helpers-in-zend-framework/</guid>
		<description><![CDATA[ Just wanted to quickly share some zend view helpers that I wrote that someone out there may find useful.
1: NF_View_Helper_EllipsisString
This helper takes a string an returns a shortened version with &#8230; tacked on. Pretty standard fair but helpful. I wrote it before I switched to Smarty for my template engine which has a similar [...]]]></description>
			<content:encoded><![CDATA[<p> Just wanted to quickly share some zend view helpers that I wrote that someone out there may find useful.</p>
<p><strong>1: NF_View_Helper_EllipsisString</strong></p>
<p>This helper takes a string an returns a shortened version with &#8230; tacked on. Pretty standard fair but helpful. I wrote it before I switched to Smarty for my template engine which has a similar function built in.</p>
<pre name="code" class="php">
class NF_View_Helper_EllipsisString
{
    //defaults to 50 chars and ...
    public function ellipsisString($string, $max = 50, $rep = '...') {
	    $leave = $max - strlen ($rep);
	    return substr_replace($string, $rep, $leave);
	}
}</pre>
<p><strong>2: NF_View_Helper_FormatDate</strong></p>
<p>This helper takes a date and gives you back a formatted version. It allowes you to pass in a format specifier string or choose from one of the predefined formats.</p>
<pre name="code" class="php">
require_once 'Zend/Date.php';

class NF_View_Helper_FormatDate
{
    private $date_formats = array("mdy"=&gt;"MMMM/dd/yy");

    public function formatDate($date, $formatName, $formatStr = '') {
	    if (!Zend_Date::isDate($date)) {
		    return $date;
		}else{
			$date = new Zend_Date($date);
			if(($formatName != null)&amp;&amp;(in_array($this-&gt;date_formats,$formatName))){
				return $date-&gt;toString($this-&gt;date_formats[$formatName]);
			}else if($formatStr != null){
				return $date-&gt;toString($formatStr);
			}
		}
	}
}</pre>
<p>Feel free to use and no you can&#8217;t blame me if it blows up and kills your family dog&#8230; What do you want for nothing?</p>
<p>Oh whats that you say? You have never used a view helper? erm well ok then&#8230; You can get the info <a href="http://framework.zend.com/manual/en/zend.view.helpers.html" target="_blank">from their docs</a> but I&#8217;ll break it down for you quickly as well.</p>
<p>If you have never used a custom view helper its really easy (as long as you follow the conventions of course). Just put them in the application/views/helpers dir (if you followed the standard MVC layout from the docs). The php files that hold the classes should be named after the function in CamelCase. So for instance the NF_View_Helper_EllipsisString plugin lives in a file called EllipsisString and contains a class called NF_View_Helper_EllipsisString with a function called ellipsisString. Even though the method name starts with a lower case e it needs to have a CamelCase in the file name and the class name. NF_View_Helper_ is a namespace which helps with organization.</p>
<p>Once you have that together inside of your controller init you call</p>
<pre name="code" class="php">
$this-&gt;view-&gt;setHelperPath('../views/helpers', 'NF_View_Helper');</pre>
<p>Now your all set to use these in calls in your views like so</p>
<pre name="code" class="php">
$this-&gt;ellipsisString("my really really really long string or whatever",10,"...");</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ninjacipher.com/2007/11/14/view-helpers-in-zend-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
