<?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>Erhan is typing... &#187; CakePHP</title> <atom:link href="http://www.erhanabay.com/category/cakephp/feed/" rel="self" type="application/rss+xml" /><link>http://www.erhanabay.com</link> <description>WebDevelopment , PHP, Javascript, CakePHP, ExtJS</description> <lastBuildDate>Wed, 11 Jan 2012 13:04:15 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>Ext.Direct for CakePHP</title><link>http://www.erhanabay.com/2009/11/28/ext-direct-for-cakephp/</link> <comments>http://www.erhanabay.com/2009/11/28/ext-direct-for-cakephp/#comments</comments> <pubDate>Sat, 28 Nov 2009 02:19:51 +0000</pubDate> <dc:creator>Erhan Abay</dc:creator> <category><![CDATA[CakePHP]]></category> <category><![CDATA[ExtJS]]></category> <category><![CDATA[Javascript]]></category> <category><![CDATA[MVC]]></category> <category><![CDATA[PHP]]></category> <guid
isPermaLink="false">http://erhanabay.com/?p=385</guid> <description><![CDATA[Finally, I completed the basic implementation of Ext.Direct server-side stack for CakePHP. You can clone a working copy from http://github.com/eabay/directcakephp. It is not that good but it works! http://www.extjs.com/forum/showthread.php?t=86501]]></description> <content:encoded><![CDATA[<p>Finally, I completed the basic implementation of Ext.Direct server-side stack for CakePHP.</p><p>You can clone a working copy from <a
href="http://github.com/eabay/directcakephp" onclick="pageTracker._trackPageview('/outgoing/github.com/eabay/directcakephp?referer=');">http://github.com/eabay/directcakephp</a>.</p><p>It is not that good but it works! <img
src='http://www.erhanabay.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><p><a
href="http://www.extjs.com/forum/showthread.php?t=86501" onclick="pageTracker._trackPageview('/outgoing/www.extjs.com/forum/showthread.php?t=86501&amp;referer=');">http://www.extjs.com/forum/showthread.php?t=86501</a></p> ]]></content:encoded> <wfw:commentRss>http://www.erhanabay.com/2009/11/28/ext-direct-for-cakephp/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>CakePHP Helper for rakaz Combine</title><link>http://www.erhanabay.com/2009/11/19/cakephp-helper-for-rakaz-combine/</link> <comments>http://www.erhanabay.com/2009/11/19/cakephp-helper-for-rakaz-combine/#comments</comments> <pubDate>Thu, 19 Nov 2009 20:49:41 +0000</pubDate> <dc:creator>Erhan Abay</dc:creator> <category><![CDATA[CakePHP]]></category> <category><![CDATA[Javascript]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[cakephp helper]]></category> <category><![CDATA[combine]]></category> <category><![CDATA[compress]]></category> <category><![CDATA[CSS]]></category> <category><![CDATA[helpers]]></category> <guid
isPermaLink="false">http://erhanabay.com/?p=373</guid> <description><![CDATA[Combine is still my favorite javascript/css combine and compress script. I posted a solution how to use it in a CakePHP application and here is a little helper to make it more useful: Add it to controller&#8217;s helpers property: And call it by passing an array of file names in your view: Don&#8217;t forget to [...]]]></description> <content:encoded><![CDATA[<p>Combine is still my favorite javascript/css combine and compress script.</p><p>I <a
href="http://erhanabay.com/2009/01/29/using-rakaz-combine-with-your-cakephp-application/" onclick="pageTracker._trackPageview('/outgoing/erhanabay.com/2009/01/29/using-rakaz-combine-with-your-cakephp-application/?referer=');">posted</a> a solution how to use it in a CakePHP application and here is a little helper to make it more useful:</p><pre class="brush: php; title: ; notranslate">
&lt;?php
//app/views/helpers/combine.php
class CombineHelper extends AppHelper
{
	public $helpers = array('Html', 'Javascript');
	private $_pattern = '../combine.php?type=:type&amp;files=:files';
	public function js($files)
	{
		echo $this-&gt;Javascript-&gt;link($this-&gt;_format($files));
	}
	public function css($files)
	{
		echo $this-&gt;Html-&gt;css($this-&gt;_format($files, 'css'));
	}
	private function _format($files = array(), $type = 'javascript')
	{
		return String::insert($this-&gt;_pattern, array('type' =&gt; $type, 'files' =&gt; implode(',', $files)));
	}
}
</pre><p>Add it to controller&#8217;s helpers property:</p><pre class="brush: php; title: ; notranslate">
&lt;?php
class MyController extends AppController
{
	public $helpers = array('Combine');
</pre><p>And call it by passing an array of file names in your view:</p><pre class="brush: php; title: ; notranslate">
$combine-&gt;js(array(
    'javascript1.js',
    'javascript2.js',
    'javascript3.js'
));
$combine-&gt;css(array(
    'stylesheet1.css',
    'stylesheet2.css',
    'stylesheet3.css'
));
</pre><blockquote><p>Don&#8217;t forget to add file extensions!</p></blockquote><blockquote><p>If you want to add only one file, you don&#8217;t have to use combine helper. Directives added to .htaccess file let combine script to compress the file(<a
href="http://erhanabay.com/2009/01/29/using-rakaz-combine-with-your-cakephp-application/" onclick="pageTracker._trackPageview('/outgoing/erhanabay.com/2009/01/29/using-rakaz-combine-with-your-cakephp-application/?referer=');">See related post</a>). Just use <em>$javascript->link(&#8216;filename&#8217;)</em>.</p></blockquote> ]]></content:encoded> <wfw:commentRss>http://www.erhanabay.com/2009/11/19/cakephp-helper-for-rakaz-combine/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Using rakaz Combine With Your CakePHP Application</title><link>http://www.erhanabay.com/2009/01/29/using-rakaz-combine-with-your-cakephp-application/</link> <comments>http://www.erhanabay.com/2009/01/29/using-rakaz-combine-with-your-cakephp-application/#comments</comments> <pubDate>Thu, 29 Jan 2009 03:42:13 +0000</pubDate> <dc:creator>Erhan Abay</dc:creator> <category><![CDATA[CakePHP]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[combine]]></category> <category><![CDATA[compress]]></category> <category><![CDATA[CSS]]></category> <guid
isPermaLink="false">http://erhanabay.com/?p=189</guid> <description><![CDATA[Combine is a small PHP script and some clever URL rewriting designed to speed up the loading of pages that use many or large css and javascript files. It is good but how can you integrate it with your CakePHP project? And solution comes with the question . Download a copy of combine.php and drop [...]]]></description> <content:encoded><![CDATA[<blockquote><p><a
href="http://rakaz.nl/extra/code/combine" onclick="pageTracker._trackPageview('/outgoing/rakaz.nl/extra/code/combine?referer=');">Combine</a> is a small PHP script and some clever URL rewriting designed to speed up the loading of pages that use many or large css and javascript files.</p></blockquote><p>It is good but how can you integrate it with your CakePHP project? And solution comes with the question <img
src='http://www.erhanabay.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p><p><a
href="http://rakaz.nl/projects/combine/combine.phps" onclick="pageTracker._trackPageview('/outgoing/rakaz.nl/projects/combine/combine.phps?referer=');">Download</a> a copy of combine.php and drop it into your &#8220;app/webroot&#8221; directory (or whatever your application folder name is XXX/webroot/).</p><p>Open the file in your text editor and change lines:</p><pre class="brush: php; title: ; notranslate">
$cachedir = dirname(__FILE__) . '/cache';
$cssdir   = dirname(__FILE__) . '/css';
$jsdir    = dirname(__FILE__) . '/javascript';
</pre><p>with</p><pre class="brush: php; title: ; notranslate">
$cachedir = dirname(__FILE__) . '/../tmp/cache';
$cssdir   = dirname(__FILE__) . '/css';
$jsdir    = dirname(__FILE__) . '/js';
</pre><p>Open your &#8220;app/webroot/.htaccess&#8221; file and add those two lines</p><pre class="brush: php; title: ; notranslate">
RewriteRule ^css/(.*\.css) combine.php?type=css&amp;files=$1
RewriteRule ^js/(.*\.js) combine.php?type=javascript&amp;files=$1
</pre><p>That&#8217;s all! Check download times of your css and javascript files with a tool like Firebug. A fatty 527KB ext-all.js javascript framework file compressed to 140KB! Amazing ha?</p><p><a
href="http://erhanabay.com/wp-content/uploads/2009/01/combinephp.jpg" onclick="pageTracker._trackPageview('/outgoing/erhanabay.com/wp-content/uploads/2009/01/combinephp.jpg?referer=');"><img
src="http://erhanabay.com/wp-content/uploads/2009/01/combinephp.jpg" alt="rakaz combine" title="rakaz combine" width="865" height="292" class="aligncenter size-full wp-image-190" /></a></p> ]]></content:encoded> <wfw:commentRss>http://www.erhanabay.com/2009/01/29/using-rakaz-combine-with-your-cakephp-application/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>CakePHP RequestHandler Extended</title><link>http://www.erhanabay.com/2009/01/29/cakephp-requesthandler-extended/</link> <comments>http://www.erhanabay.com/2009/01/29/cakephp-requesthandler-extended/#comments</comments> <pubDate>Thu, 29 Jan 2009 03:14:34 +0000</pubDate> <dc:creator>Erhan Abay</dc:creator> <category><![CDATA[CakePHP]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[components]]></category> <category><![CDATA[extending cakephp component]]></category> <guid
isPermaLink="false">http://erhanabay.com/?p=181</guid> <description><![CDATA[A CakePHP component which extends built-in RequestHandler component by adding some useful geolocation information. It requires MaxMind WebService license key to work properly. Save it with the name request_handler_ext.php into your application components directory under controllers. You can call the following methods within your controller (e.g. $this->RequestHandlerExt->methodName()): getClientCountryCode() : ISO 3166 Two-letter Country Code getClientRegionCode() [...]]]></description> <content:encoded><![CDATA[<p>A CakePHP component which extends built-in RequestHandler component by adding some useful geolocation information. It requires MaxMind WebService license key to work properly.</p><p>Save it with the name request_handler_ext.php into your application components directory under controllers.</p><p>You can call the following methods within your controller (e.g. $this->RequestHandlerExt->methodName()):</p><blockquote><p> getClientCountryCode() : ISO 3166 Two-letter Country Code<br
/> getClientRegionCode() : Region Code<br
/> getClientCity() : City<br
/> getClientPostalCode() : Postal Code<br
/> getClientLatitude() : Latitude<br
/> getClientLongitude() : Longitude<br
/> getClientMetropolitanCode() : Metropolitan Code<br
/> getClientMetropolitanCode() : Area Code<br
/> getClientIsp() : ISP<br
/> getClientOrganization() : Organization</p></blockquote><pre class="brush: php; title: ; notranslate">
&lt;?php
/**
 * Extends RequestHandler component by adding some useful geolocation information.
 *
 * Requires MaxMind WebService license key to work properly
 *
 * @copyright     2009 Erhan Abay
 * @package       app
 * @subpackage    app.controllers.components
 * @version       $Revision$
 * @lastmodified  $Date$
 */
App::import('Component', 'RequestHandler');
class RequestHandlerExtComponent extends RequestHandlerComponent
{
	/**
	 * Required to query MaxMind WebService
	 *
	 * Provide your own key by replacing XXXXX.
	 */
	const MM_LICENSE_KEY = 'XXXXXX';
	public function startup(&amp;amp;amp;amp;amp;$controller)
	{
		parent::startup(&amp;amp;amp;amp;amp;$controller);
		$this-&gt;controller =&amp;amp;amp;amp;amp; $controller;
	}
	/**
	 * Searches key value in array returned by function getGeoLocation()
	 *
	 * @param string $name Name of the method
	 * @param unknown_type $arguments Not used, required not to give error
	 * @return string if key found
	 *         null else
	 */
	public function __call($name, $raw = false)
	{
		$var = Inflector::underscore(preg_replace('/getClient/i', '', $name));
		$geo_location = (array)$this-&gt;getGeoLocation($raw);
		return array_key_exists($var, $geo_location) ? $geo_location[$var] : null;
	}
	/**
	 * Queries to the MaxMind WebService and returns an array of information
	 *
	 * @param bool $raw
	 * @return null if IP address is local
	 *         bool false if webservice returns error code
	 *         string if $raw is set true
	 *         array else
	 */
  public function getGeoLocation($raw = false)
  {
  	if ($this-&gt;isLocalIP()) {
  		return null;
  	}
  	if ($this-&gt;controller-&gt;Session-&gt;check('User.GeoLocation')) {
  		return $raw ? $this-&gt;controller-&gt;Session-&gt;read('User.GeoLocation.raw') : $this-&gt;controller-&gt;Session-&gt;read('User.GeoLocation');
  	}
    App::import('HttpSocket');
    $http = new HttpSocket();
    /*
     * Returns in order:
     *
     * 0  ISO 3166 Two-letter Country Code,
     * 1  Region Code,
     * 2  City,
     * 3  Postal Code,
     * 4  Latitude,
     * 5  Longitude,
     * 6  Metropolitan Code,
     * 7  Area Code,
     * 8  ISP,
     * 9  Organization,
     * 10 Error code
     */
    $result = $http-&gt;get('http://geoip1.maxmind.com/f', array(
      'l' =&gt; self::MM_LICENSE_KEY,
      'i' =&gt; $this-&gt;getClientIP()
    ));
    $values = explode(',', $result);
    if (isset($values[10])) {
      return false;
    }
    if ($raw) {
    	return $result;
    }
    $keys = array('country_code', 'region_code', 'city', 'postal_code', 'latitude', 'longitude', 'metropolitan_code', 'area_code', 'isp', 'organization');
    $data = array_combine($keys, $values);
    $data['coords'] = $values[4].','.$values[5];
    $data['raw'] = $result;
    $this-&gt;controller-&gt;Session-&gt;write('User.GeoLocation', $data);
    return $data;
  }
  /**
   * Detects whether IP address is local or not
   *
   * @param string $ip IP address to check
   * @return bool
   */
  public function isLocalIP($ip = null) {
  	$ip = is_null($ip) ? $this-&gt;getClientIP() : $ip;
  	$regex = '/(192\.168\.[0-9]{1,3}\.[0-9]{1,3})';
	$regex .= '|(10\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})';
	$regex .= '|(172\.0?([1][6-9])Â¦([2][0-9])Â¦([3][0-1])\.[0-9]{1,3}\.[0-9]{1,3})';
	$regex .= '|(127\.0\.0\.1)/';
  	return (bool)preg_match($regex, $ip);
  }
}
?&gt;
</pre>]]></content:encoded> <wfw:commentRss>http://www.erhanabay.com/2009/01/29/cakephp-requesthandler-extended/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Make CakePHP Email Component Reusable</title><link>http://www.erhanabay.com/2009/01/29/make-cakephp-email-component-reusable/</link> <comments>http://www.erhanabay.com/2009/01/29/make-cakephp-email-component-reusable/#comments</comments> <pubDate>Thu, 29 Jan 2009 02:52:36 +0000</pubDate> <dc:creator>Erhan Abay</dc:creator> <category><![CDATA[CakePHP]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[components]]></category> <category><![CDATA[extending cakephp component]]></category> <guid
isPermaLink="false">http://erhanabay.com/?p=175</guid> <description><![CDATA[I know the title of this post a little bit confusing but let me explain what I want to tell. You are using CakePHP&#8216;s email component and you should set the same information in each time before you send your email like server address, username, password etc. Just create a new file mailer.php with the [...]]]></description> <content:encoded><![CDATA[<p>I know the title of this post a little bit confusing but let me explain what I want to tell.</p><p>You are using <a
href="http://cakephp.org" onclick="pageTracker._trackPageview('/outgoing/cakephp.org?referer=');">CakePHP</a>&#8216;s email component and you should set the same information in each time before you send your email like server address, username, password etc.</p><p>Just create a new file mailer.php with the following content and drop it into your CakePHP application components folder (I like convention over configuration! <img
src='http://www.erhanabay.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> ).</p><pre class="brush: php; title: ; notranslate">
&lt;?php
App::import('Component', 'Email');
class MailerComponent extends EmailComponent
{
  var $from = 'ME &lt;me@localhost&gt;';
  var $replyTo = 'noreply@localhost';
  var $sendAs = 'both';
  var $delivery = 'smtp';
  var $xMailer = 'Postman';
  var $smtpOptions = array(
    'port'=&gt; 25,
    'host' =&gt; 'serveradress',
    'timeout' =&gt; 30,
    'username' =&gt; 'username',
    'password' =&gt; 'password'
  );
}
?&gt;
</pre><p>And right now you have a new component with the name &#8220;Mailer&#8221; and its server configuration is predefined. You can reuse it without being affected by any kind of mail server change.</p><p>You can define a new function inside your controller (_sendEmail() in our case) and make the email sending process more painless.</p><pre class="brush: php; title: ; notranslate">
class AnyController extends AppController
{
  function contact()
  {
    if ($this-&gt;_sendEmail('Name', 'blabla@fakeemail', 'Grate site!')) {
      $this-&gt;Session-&gt;setFlash(__(&quot;Thank you&quot;, true));
    } else {
      $this-&gt;Session-&gt;setFlash('Damn it!');
    }
  }
  function _sendEmail($name, $email, $message)
  {
    $this-&gt;Mailer-&gt;to = 'info@localhost';
    $this-&gt;Mailer-&gt;subject = __(&quot;Site Contact&quot;, true);
    $this-&gt;Mailer-&gt;template = 'contact';
    $this-&gt;set('name', $name);
    $this-&gt;set('email', $email);
    $this-&gt;set('message', $message);
    $this-&gt;Mailer-&gt;send();
    $this-&gt;log( $this-&gt;Mailer-&gt;subject . ' -&gt; Name:'. $name .' | E-posta: '. $email .' | Message: '. $message .' | smtp error: '. serialize($this-&gt;Mailer-&gt;smtpError) );
    return $this-&gt;Mailer-&gt;smtpError ? false : true;
  }
}
</pre><p>That&#8217;s all! Check <a
href="http://bakery.cakephp.org/" onclick="pageTracker._trackPageview('/outgoing/bakery.cakephp.org/?referer=');">Bakery</a> for other cakes <img
src='http://www.erhanabay.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p> ]]></content:encoded> <wfw:commentRss>http://www.erhanabay.com/2009/01/29/make-cakephp-email-component-reusable/feed/</wfw:commentRss> <slash:comments>6</slash:comments> </item> </channel> </rss>
