<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Fernando Marcelo.com</title>
	
	<link>http://fernandomarcelo.com</link>
	<description>Just some dev stuff.</description>
	<lastBuildDate>Fri, 11 May 2012 02:00:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/FernandoMarcelo" /><feedburner:info uri="fernandomarcelo" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>FernandoMarcelo</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>Rails Admin: creating a custom action</title>
		<link>http://feedproxy.google.com/~r/FernandoMarcelo/~3/4V7bb78JxX8/</link>
		<comments>http://fernandomarcelo.com/2012/05/rails-admin-creating-a-custom-action/#comments</comments>
		<pubDate>Fri, 11 May 2012 01:59:24 +0000</pubDate>
		<dc:creator>Fernando Morgenstern</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[rails admin]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://fernandomarcelo.com/?p=76</guid>
		<description><![CDATA[Rails Admin is an excellent way of quickly creating a backend for your website. It&#8217;s simply perfect for that project that is focused on frontend but you still need a backend to do simple management tasks. Although it&#8217;s very complete, sometimes you may want to customize a few things and for this you can create [...]]]></description>
			<content:encoded><![CDATA[<p>Rails Admin is an excellent way of quickly creating a backend for your website. It&#8217;s simply perfect for that project that is focused on frontend but you still need a backend to do simple management tasks.</p>
<p>Although it&#8217;s very complete, sometimes you may want to customize a few things and for this you can create a custom action.</p>
<p><span id="more-76"></span></p>
<p>If you have, for example, a list of articles. It would be good if you could bulk publish them, instead of going and editing one by one. Fortunately this is possible and quite simple, although it&#8217;s not very clear in Rails Admin manual.</p>
<p><strong>1. Create your custom action</strong></p>
<p>Let&#8217;s create our custom action. Create file <strong>lib/rails_admin_publish.rb</strong> with the following content:</p>
<pre class="brush: ruby; title: ; notranslate">
require 'rails_admin/config/actions'
require 'rails_admin/config/actions/base'

module RailsAdminPublish
end

module RailsAdmin
  module Config
    module Actions
      class Publish &lt; RailsAdmin::Config::Actions::Base
        # There are several options that you can set here.
        # Check https://github.com/sferik/rails_admin/blob/master/lib/rails_admin/config/actions/base.rb for more info.

        register_instance_option :bulkable? do
          true
        end

        register_instance_option :controller do
          Proc.new do
            # Get all selected rows
            @objects = list_entries(@model_config, :destroy)

            # Update field published to true
            @objects.each do |object|
              object.update_attribute(:published, true)
            end

            flash[:success] = &quot;#{@model_config.label} successfully published.&quot;

            redirect_to back_or_index
          end
        end
      end
    end
  end
end
</pre>
<p>What exactly this does? Well, first it defines this action as bulkable. There are many other options that you can set here, check the comment next to that line for more information.</p>
<p>After that, we create a Proc with our action. In summary, it&#8217;s getting all entries and looping to update the attribute published. After that, it sets a flash message and redirect to index.</p>
<p><strong>2. Let Rails Admin know that your custom action exists</strong></p>
<p>Open <strong>config/initializers/rails_admin.rb</strong> and add the following code <strong>before</strong> RailsAdmin.config:</p>
<pre class="brush: ruby; title: ; notranslate">require Rails.root.join('lib', 'rails_admin_publish.rb')</pre>
<p>Them add this <strong>inside</strong> RailsAdmin.config:</p>
<pre class="brush: ruby; title: ; notranslate">
# Register the class in lib/rails_admin_publish.rb
module RailsAdmin
  module Config
    module Actions
      class Publish &lt; RailsAdmin::Config::Actions::Base
        RailsAdmin::Config::Actions.register(self)
      end
    end
  end
end

c.actions do
  # root actions
  dashboard                     # mandatory
  # collection actions
  index                         # mandatory
  new
  export
  history_index
  bulk_delete
  # member actions
  show
  edit
  delete
  history_show
  show_in_app

  # Set the custom action here
  publish do
    # Make it visible only for article model. You can remove this if you don't need.
    visible do
      bindings[:abstract_model].model.to_s == &quot;Article&quot;
    end
  end
end
</pre>
<p>What it does is to first register the publish action and them tell Rails Admin where it should be visible. If you want to make it visible for all models, simply remove that visible part and it should work correctly.</p>
<p>That&#8217;s it, restart your server and test. The bulk action should be there.</p>
<p>In case you still have questions I&#8217;ve forked dummy_app, which is a sample app created to show Rails Admin, and used it to create a custom action. Check it out in Github <a href="https://github.com/fernandomm/dummy_app">https://github.com/fernandomm/dummy_app</a></p>
<img src="http://feeds.feedburner.com/~r/FernandoMarcelo/~4/4V7bb78JxX8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://fernandomarcelo.com/2012/05/rails-admin-creating-a-custom-action/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://fernandomarcelo.com/2012/05/rails-admin-creating-a-custom-action/</feedburner:origLink></item>
		<item>
		<title>Paperclip: how to move existing attachments to a new path</title>
		<link>http://feedproxy.google.com/~r/FernandoMarcelo/~3/oG1jpRA_OHk/</link>
		<comments>http://fernandomarcelo.com/2012/05/paperclip-how-to-move-existing-attachments-to-a-new-path/#comments</comments>
		<pubDate>Thu, 10 May 2012 03:17:37 +0000</pubDate>
		<dc:creator>Fernando Morgenstern</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[paperclip]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://fernandomarcelo.com/?p=68</guid>
		<description><![CDATA[I made the mistake of using the default Paperclip url/path for multiple models, which is problem if an user upload a file with the same name and id, causing a conflict. Also, using the same directory for different models is kind of messy. Here are the steps that i took to fix this problem: 1. [...]]]></description>
			<content:encoded><![CDATA[<p>I made the mistake of using the default Paperclip url/path for multiple models, which is problem if an user upload a file with the same name and id, causing a conflict. Also, using the same directory for different models is kind of messy.</p>
<p>Here are the steps that i took to fix this problem:</p>
<p><span id="more-68"></span></p>
<p><strong>1. Change the path/url in model</strong></p>
<p>Before:</p>
<pre class="brush: ruby; title: ; notranslate">
class User &lt; ActiveRecord::Base
  has_attached_file :image
end
</pre>
<p>After:</p>
<pre class="brush: ruby; title: ; notranslate">
class User &lt; ActiveRecord::Base
  has_attached_file :image,
     :path =&gt; &quot;:rails_root/public/system/users/images/:id/:style/:filename&quot;,
     :url =&gt; &quot;/system/users/images/:id/:style/:filename&quot;
end
</pre>
<p>This will make them to be stored in public/system/users/images/. If you have other models like Post or Article, edit them too but use different paths.</p>
<p><strong>2. Move your current data</strong></p>
<p>If you already have some files, it&#8217;s time to move them as Paperclip won&#8217;t do it for you. To do it i created a rake task. Place it in <strong>lib/tasks/copy_paperclip_data.rb</strong>:</p>
<pre class="brush: ruby; title: ; notranslate">
desc &quot;Copy paperclip data&quot;
task :copy_paperclip_data =&gt; :environment do
  @users = User.find :all
  @users.each do |user|
    unless user.image_file_name.blank?
      filename = Rails.root.join('public', 'system', 'images', user.id.to_s, 'original', user.image_file_name)

      if File.exists? filename
        image = File.new filename
        user.image = image
        user.save

        image.close
      end
    end
  end
end
</pre>
<p>You probably have to adapt this in case you are working on another model or field. In this case, i&#8217;m working on model Users and field image.</p>
<p>Note that i&#8217;m <strong>copying data</strong>. In case something goes wrong, you can revert it back. Remove it after you&#8217;re done.</p>
<p>Now simply run:</p>
<pre class="brush: plain; title: ; notranslate">
rake copy_paperclip_data
</pre>
<p>Hope this helps you.</p>
<img src="http://feeds.feedburner.com/~r/FernandoMarcelo/~4/oG1jpRA_OHk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://fernandomarcelo.com/2012/05/paperclip-how-to-move-existing-attachments-to-a-new-path/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://fernandomarcelo.com/2012/05/paperclip-how-to-move-existing-attachments-to-a-new-path/</feedburner:origLink></item>
		<item>
		<title>Uncaught exception ‘Zend_Application_Resource_Exception’ with message ‘Bootstrap file found for module “default”</title>
		<link>http://feedproxy.google.com/~r/FernandoMarcelo/~3/XZbMujKh3xo/</link>
		<comments>http://fernandomarcelo.com/2011/08/uncaught-exception-zend_application_resource_exception-with-message-bootstrap-file-found-for-module-default/#comments</comments>
		<pubDate>Tue, 09 Aug 2011 01:57:03 +0000</pubDate>
		<dc:creator>Fernando Morgenstern</dc:creator>
				<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[zend framework exceptions]]></category>

		<guid isPermaLink="false">http://fernandomarcelo.com/?p=59</guid>
		<description><![CDATA[Getting this error after moving your ZF application to use modules? Fatal error: Uncaught exception 'Zend_Application_Resource_Exception' with message 'Bootstrap file found for module "default" but bootstrap class "Default_Bootstrap" not found' This usually happens if you declare your controllerDirectory on Front Controller before defining a different defaultModule. Something like this on application.ini: resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers" resources.frontController.defaultModule [...]]]></description>
			<content:encoded><![CDATA[<p>Getting this error after moving your ZF application to use modules?</p>
<pre>Fatal error: Uncaught exception 'Zend_Application_Resource_Exception'
with message 'Bootstrap file found for module "default" but
bootstrap class "Default_Bootstrap" not found'</pre>
<p>This usually happens if you declare your <strong>controllerDirectory</strong> on Front Controller <strong>before</strong> defining a different <strong>defaultModule</strong>.</p>
<p>Something like this on application.ini:</p>
<pre>resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.defaultModule = "core"</pre>
<p>Removing controllerDirectory declaration should do the trick ( it&#8217;s not necessary since you are using modules ).</p>
<p>Or, you can simply place it below defaultModule declaration.</p>
<img src="http://feeds.feedburner.com/~r/FernandoMarcelo/~4/XZbMujKh3xo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://fernandomarcelo.com/2011/08/uncaught-exception-zend_application_resource_exception-with-message-bootstrap-file-found-for-module-default/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://fernandomarcelo.com/2011/08/uncaught-exception-zend_application_resource_exception-with-message-bootstrap-file-found-for-module-default/</feedburner:origLink></item>
		<item>
		<title>What makes ZF a brilliant framework and what makes it sucks?</title>
		<link>http://feedproxy.google.com/~r/FernandoMarcelo/~3/dPMY3s7aF18/</link>
		<comments>http://fernandomarcelo.com/2011/01/what-makes-zf-a-brilliant-framework-and-what-make-it-sucks/#comments</comments>
		<pubDate>Thu, 13 Jan 2011 22:01:26 +0000</pubDate>
		<dc:creator>Fernando Morgenstern</dc:creator>
				<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://fernandomarcelo.com/?p=46</guid>
		<description><![CDATA[The purpose of this post is to give an introduction about Zend Framework. Even if you are not a PHP developer, you may be interested in reading it to know what have been &#8220;going on&#8221; in the PHP world. With so many technologies coming up, sometimes is difficult to analyze all of them in order [...]]]></description>
			<content:encoded><![CDATA[<p>The purpose of this post is to give an introduction about Zend Framework. Even if you are not a PHP developer, you may be interested in reading it to know what have been &#8220;going on&#8221; in the PHP world.</p>
<p>With so many technologies coming up, sometimes is difficult to analyze all of them in order to know which will fit better in your project. The purpose of this post is to show what makes ZF different from other solutions around. So let&#8217;s start&#8230;</p>
<p>Zend Framework is PHP MVC framework. It&#8217;s fully OOP and is actively developed. So far nothing exceptional, right? So let me show you some of the things that make it different.</p>
<h3>1. Translation and localization done right!</h3>
<p>The ZF developers have taken care of allowing translation of every component in brilliant way.  Not everyone speaks English and it sucks to start using a component and find out that you can&#8217;t easily translate the error messages, which are in English.</p>
<p>Zend Locale wonderfully does its job by detecting the language and country/region of the user and allowing others components to make use of this information.</p>
<ul>
<li>Zend Currency will know the currency symbol of the user&#8217;s country.<br />
Eg.: <strong>$ 4.00</strong> for Americans and R$ 4,00 for Brazilians.</li>
</ul>
<ul>
<li>If you have a Zend Form field declared as float, it will flawless validate depending  if user uses comma or dots as decimal symbols.<br />
Eg.: <strong>1.23 </strong>for Americans and <strong>1,23</strong> for Brazilians</li>
</ul>
<ul>
<li>Zend Route will take care to make the urls of your website fully localized, improving SEO.<br />
Eg.: <strong>/contact-us/</strong> for Americans and <strong>/contacte-nos/</strong> for Brazilians.</li>
</ul>
<ul>
<li>And we can&#8217;t forget Zend Date, which will show the date in a way that user understand.<br />
Eg.: <strong>12/31/2010</strong> for Americans and <strong>31/12/2010</strong> for Brazilians.</li>
</ul>
<ul>
<li>There is much more, but i can&#8217;t write all night <img src='http://fernandomarcelo.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
</ul>
<p>And no, you don&#8217;t have to manually insert this info. It doesn&#8217;t matter if your user is from Brazil, USA, Russia or India, their localization info is already in the framework ready to use.</p>
<h3>2. High number of well tested and useful components.</h3>
<p>Zend Framework offers a vast number of components for different purposes ( checkout <a href="http://www.zendframework.com/manual/en/reference.html">their page</a> to see all of them ) They are well tested as the framework development is test driven, so closed bugs are very unlikely to come back.</p>
<p>Whether you are trying to access your twitter account, getting a video info from Youtube or creating a tag cloud for your website, there are components for it saving you a lot of time.</p>
<h3>3. Get used to the components and use them, everywhere.</h3>
<p>Zend Framework is separated in components and it allows you to use them separately without requiring the full framework structure. There are, of course, some components with dependencies but most of them can be used alone.</p>
<p>Example, you can get the Zend Pdf component and use it in a project with Code Igniter or Cake PHP framework.</p>
<p>So, once you start working more and more with ZF but them have to work on another project, you will be able to use the same components that you are already used for.</p>
<h3>4. Let&#8217;s bring some coding standards to PHP.</h3>
<p>I have to admit, PHP sucks in coding standards. Even on the modules included in language you will find function&#8217;s name written in camelCase and functions written with underscore ( no_camel_case ).</p>
<p>It&#8217;s not good when you get some code from another developer and he is using camelCase while you are used to use underscores.</p>
<p>Another example are brackets. On an if condition, some developers likes to use in the same line, others in the next line.</p>
<p>The discussion here isn&#8217;t which is best, but there must be a standard so that, next time you get a code, you won&#8217;t get a bizarre monster made by 5 developers with their own preferences.</p>
<p>ZF clearly dictates some coding standards that you have to follow. All components in the framework use this standard and most of the code that you get is using it too.</p>
<h3>5. If there is a standard, use it! Do not create your own!</h3>
<p>Another thing that developers have taken care of is to use standards. It&#8217;s horrible to get new component that doesn&#8217;t follow any standards in its area and tries to create its own. Specially when you already know the standard.</p>
<p>An example:</p>
<p>PHP date&#8217;s function consider <strong>m </strong>as month char and <strong>i</strong> as minute char. It&#8217;s ok, but other&#8217;s libraries considers <strong>o </strong>for month and <strong>m </strong>for minute.</p>
<p>This is a simple example but when you are dealing with complex stuff, it can make you lose a lot of time.</p>
<p>Zend Date implementation uses ISO 8601 standard. Damn, there is a ISO standard for this, why will you create your own?</p>
<h3>Ok, but what make it sucks?</h3>
<p>I have written only a few aspects that make ZF rocks. So I will save some of them for a next post. Let&#8217;s talk about what make it sucks.</p>
<p>The main thing that still sucks in Zend Framework is the documentation. Although all components are documented there are too few examples and some of them do not work correctly, requiring some changes to achieve their purpose.</p>
<p>This is bad specially when you are learning something new. I often have to dig in the code of a component to find how a feature works. Sometimes because the example in manual is wrong and sometimes because the manual simply ignore the feature that i am trying to use.</p>
<p>Fortunately the developers are aware of this and one of the things which will be worked in version 2.0 is a better manual specially for people that are starting with the framework. Let&#8217;s hope that they can improve this <img src='http://fernandomarcelo.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h3>Conclusion</h3>
<p>I have been working with Zend Framework for approximately 2 years and it has been a fun and productive experience.I am doing things much faster ( and IMO, cleaner ) than with any other framework that i worked before, like CodeIgniter or Symfony.</p>
<p>Unfortunately i cannot work with it full time because of other projects, but whenever a new project shows up, ZF is always my first choice as i know that it will save a lot of time.</p>
<p>Learning a new framework is a hard task. At the beginning you have to &#8220;learn again&#8221; lots of things and sometimes change your way of solving some kind of problems. With ZF is not different, but i would really recommend that you give it a try. I haven&#8217;t regretted at all!</p>
<img src="http://feeds.feedburner.com/~r/FernandoMarcelo/~4/dPMY3s7aF18" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://fernandomarcelo.com/2011/01/what-makes-zf-a-brilliant-framework-and-what-make-it-sucks/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://fernandomarcelo.com/2011/01/what-makes-zf-a-brilliant-framework-and-what-make-it-sucks/</feedburner:origLink></item>
		<item>
		<title>Get date in Mysql format from Zend Date</title>
		<link>http://feedproxy.google.com/~r/FernandoMarcelo/~3/_aoc1gLjW48/</link>
		<comments>http://fernandomarcelo.com/2010/10/get-date-in-mysql-format-from-zend-date/#comments</comments>
		<pubDate>Mon, 25 Oct 2010 21:14:51 +0000</pubDate>
		<dc:creator>Fernando Morgenstern</dc:creator>
				<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[zend date]]></category>
		<category><![CDATA[zend framework]]></category>

		<guid isPermaLink="false">http://fernandomarcelo.com/?p=38</guid>
		<description><![CDATA[If you using ZF there is a high chance that you also using Zend Date when dealing with date and time. One day you might need to get the date from a Zend Date object into Mysql format, but you will find out that none of the constants provides this. It&#8217;s a decision from developers [...]]]></description>
			<content:encoded><![CDATA[<p>If you using ZF there is a high chance that you also using Zend Date when dealing with date and time.</p>
<p>One day you might need to get the date from a Zend Date object into Mysql format, but you will find out that none of the constants provides this. It&#8217;s a decision from developers to don&#8217;t mix database stuff with Zend Date.</p>
<p>Fortunately there is an easy way of doing this. If you have date fields on Mysql, you can use:</p>
<pre class="brush: php; title: ; notranslate">$date = new Zend_Date();

// Date field
echo $date-&gt;get('yyyy-MM-dd');

// Date time field
echo $date-&gt;get('yyyy-MM-dd HH:mm:ss');</pre>
<p>But hold on, don&#8217;t start to write &#8216;yyyy-MM-dd&#8217; everywhere on your application. If one day you change your database engine, or use a MySQL server with a different locale, you will need a good search and replace software to do it.</p>
<p>Instead of it, you can use a class with constants for the two field types. In this example i called the class Fm_Utils, but you can use the name that fits better on your application:</p>
<pre class="brush: php; title: ; notranslate">&lt;?php
class Fm_Utils
{
    const DATABASE_DATE = 'yyyy-MM-dd';
    const DATABASE_DATETIME = 'yyyy-MM-dd HH:mm:ss';
}</pre>
<p>Now you can simple use this to get date in Mysql format:</p>
<pre class="brush: php; title: ; notranslate">$date = new Zend_Date();

// Date field
echo $date-&gt;get(Fm_Utils::DATABASE_DATE);

// Date time field
echo $date-&gt;get(Fm_Utils::DATABASE_DATETIME);</pre>
<p>And if one day you need to change your data platform, simply change the constant on this class.</p>
<img src="http://feeds.feedburner.com/~r/FernandoMarcelo/~4/_aoc1gLjW48" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://fernandomarcelo.com/2010/10/get-date-in-mysql-format-from-zend-date/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://fernandomarcelo.com/2010/10/get-date-in-mysql-format-from-zend-date/</feedburner:origLink></item>
		<item>
		<title>Starting to use github</title>
		<link>http://feedproxy.google.com/~r/FernandoMarcelo/~3/StwXnRHT6ws/</link>
		<comments>http://fernandomarcelo.com/2010/10/starting-to-use-github/#comments</comments>
		<pubDate>Thu, 14 Oct 2010 22:58:39 +0000</pubDate>
		<dc:creator>Fernando Morgenstern</dc:creator>
				<category><![CDATA[Others]]></category>
		<category><![CDATA[github]]></category>

		<guid isPermaLink="false">http://fernandomarcelo.com/?p=35</guid>
		<description><![CDATA[From now on, i will be using github to post the code used on all tutorials. I am still learning more about git, but it seems like a great tool Here is the repository for all blog tutorials: http://github.com/fernandomm/Blog-Tutorials]]></description>
			<content:encoded><![CDATA[<p>From now on, i will be using github to post the code used on all tutorials.</p>
<p>I am still learning more about git, but it seems like a great tool <img src='http://fernandomarcelo.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Here is the repository for all blog tutorials: <a href="http://github.com/fernandomm/Blog-Tutorials">http://github.com/fernandomm/Blog-Tutorials</a></p>
<img src="http://feeds.feedburner.com/~r/FernandoMarcelo/~4/StwXnRHT6ws" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://fernandomarcelo.com/2010/10/starting-to-use-github/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://fernandomarcelo.com/2010/10/starting-to-use-github/</feedburner:origLink></item>
		<item>
		<title>How to identify the Zend Framework version?</title>
		<link>http://feedproxy.google.com/~r/FernandoMarcelo/~3/1mNH0IIkdfg/</link>
		<comments>http://fernandomarcelo.com/2010/09/how-to-identify-the-zend-framework-version/#comments</comments>
		<pubDate>Wed, 22 Sep 2010 23:27:38 +0000</pubDate>
		<dc:creator>Fernando Morgenstern</dc:creator>
				<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[version]]></category>
		<category><![CDATA[zend framework]]></category>

		<guid isPermaLink="false">http://fernandomarcelo.com/?p=32</guid>
		<description><![CDATA[Quick tip today. If you need to identify the current Zend Framework version use: Which will result in something like this: 1.10.8. Or open file Zend/Version.php and verify constant VERSION.]]></description>
			<content:encoded><![CDATA[<p>Quick tip today. If you need to identify the current Zend Framework version use:</p>
<pre class="brush: php; title: ; notranslate">

echo Zend_Version::VERSION;
</pre>
<p>Which will result in something like this: <strong>1.10.8</strong>.</p>
<p>Or open file <strong>Zend/Version.php</strong> and verify constant VERSION.</p>
<img src="http://feeds.feedburner.com/~r/FernandoMarcelo/~4/1mNH0IIkdfg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://fernandomarcelo.com/2010/09/how-to-identify-the-zend-framework-version/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://fernandomarcelo.com/2010/09/how-to-identify-the-zend-framework-version/</feedburner:origLink></item>
		<item>
		<title>Understanding the Zend Framework bootstrap</title>
		<link>http://feedproxy.google.com/~r/FernandoMarcelo/~3/EVhwowX5oEU/</link>
		<comments>http://fernandomarcelo.com/2010/09/understanding-the-zend-framework-bootstrap/#comments</comments>
		<pubDate>Sun, 19 Sep 2010 12:56:35 +0000</pubDate>
		<dc:creator>Fernando Morgenstern</dc:creator>
				<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[bootstrap]]></category>
		<category><![CDATA[zend framework]]></category>

		<guid isPermaLink="false">http://fernandomarcelo.com/?p=21</guid>
		<description><![CDATA[ZF Version: 1.10.8 The objetive of this article is to explain how Zend Framework bootstrap works and, at a second part, show samples of bootstrap for common components. The bootstrap class is used to load common components or resources that are used by all or most of your controllers, views etc. On &#8220;non-framework&#8221; applications it [...]]]></description>
			<content:encoded><![CDATA[<p>ZF Version: 1.10.8</p>
<p>The objetive of this article is to explain how Zend Framework bootstrap works and, at a second part, show samples of bootstrap for common components.</p>
<p>The bootstrap class is used to load common components or resources that are used by all or most of your controllers, views etc. On &#8220;non-framework&#8221; applications it is common to have something like <strong>includes/common.php </strong>to &#8220;bootstrap&#8221; your application.</p>
<p>At this place you usually:</p>
<ul>
<li>Connect to database;</li>
<li>Start session;</li>
<li>Load config files;</li>
<li>Load common libraries;</li>
</ul>
<p>On ZF bootstrap, the idea is almost the same. Let&#8217;s now, try with an example. Consider the following empty bootstrap:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{

}
</pre>
<p>With ZF, all bootstrap methods starts with <strong>_init </strong>and are <strong>protected</strong>. Example:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
        protected function _initMonkeyAttack()
        {
                // Do your thing here
        }
}
</pre>
<p>This is just an example and you should always use things that describe what the method is doing. Unless you are really starting a monkey attack ( in this case, call me! ) change to something else.</p>
<p>Anything that starts with _init will be executed before application bootstrap.</p>
<h3>What if i need to run method1 before method2?</h3>
<p>It is common to require that one method is only called after another one. Example: the method that starts session should only start after the method that loads database, since your sessions are stored on database.</p>
<p>In this case, you can use $this-&gt;bootstrap( &#8216;nameOfTheMethod&#8217; ); which will load a resource before the current one. Example:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
	protected function _initDb()
	{
		// Start database connection here
	}

	protected function _initSession()
	{
		// Bootstrap db first
		$this-&gt;bootstrap( 'db' );

		// Now start session
	}
}
</pre>
<p>That&#8217;s it. This is the first part of this article.  At the second part i will show bootstrap for common components like Zend_Db, Zend_Session, Zend_Translate, Zend_Locale etc.</p>
<img src="http://feeds.feedburner.com/~r/FernandoMarcelo/~4/EVhwowX5oEU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://fernandomarcelo.com/2010/09/understanding-the-zend-framework-bootstrap/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://fernandomarcelo.com/2010/09/understanding-the-zend-framework-bootstrap/</feedburner:origLink></item>
		<item>
		<title>Using Zend_Service_Twitter and Zend_OAuth</title>
		<link>http://feedproxy.google.com/~r/FernandoMarcelo/~3/WiYVOLwrCDI/</link>
		<comments>http://fernandomarcelo.com/2010/09/using-zend_service_twitter-and-zend_oauth/#comments</comments>
		<pubDate>Sat, 18 Sep 2010 15:55:17 +0000</pubDate>
		<dc:creator>Fernando Morgenstern</dc:creator>
				<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[oauth]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[zend framework]]></category>

		<guid isPermaLink="false">http://fernandomarcelo.com/?p=5</guid>
		<description><![CDATA[ZF Version: 1.10.8 The source code of this post is available at GitHub. At this short tutorial i will show to how use Zend_Service_Twitter and Zend_OAuth. I&#8217;m considering that: You have a working ZF environment. You have registered your application at Twitter.com and have the consumer key and secret. I won&#8217;t get into the details [...]]]></description>
			<content:encoded><![CDATA[<p>ZF Version: 1.10.8</p>
<p>The source code of this post is available at <a href="http://github.com/fernandomm/Blog-Tutorials/tree/master/ZendTwitterOAuth/">GitHub</a>.</p>
<p>At this short tutorial i will show to how use Zend_Service_Twitter and Zend_OAuth. I&#8217;m considering that:</p>
<ol>
<li>You have a working ZF environment.</li>
<li> You have registered your application at Twitter.com and have the consumer key and secret.</li>
</ol>
<p>I won&#8217;t get into the details of how OAuth work, since there are many tutorials about it. But to summarize what our controller will do:</p>
<ol>
<li>User access authenticate action and it&#8217;s redirected to Twitter.com</li>
<li>If user allow application access, he gets back to our application on callback action.</li>
<li>Callback action process the request and if user is authenticated, redirect to index action.</li>
<li>Index action uses twitter service class to get user timeline ( or do other actions ).</li>
</ol>
<p>The first thing is to define a few configuration parameters. Since they are common between your controller actions, we will place it at <strong>application.ini</strong>. So open file applications/configs/application.ini and add the following lines:</p>
<pre class="brush: plain; title: ; notranslate">twitter.callbackUrl = &quot;http://localhost/twitter/callback&quot;
twitter.siteUrl = &quot;http://twitter.com/oauth&quot;
twitter.consumerKey = &quot;yourConsumerKey&quot;
twitter.consumerSecret = &quot;yourConsumerSecret&quot;</pre>
<p>The directives are self explanatory, just make sure that the callback url is set to the correct action.</p>
<p>Now that you have the config, let&#8217;s create a controller for it. In this example, it will be called twitter:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

class TwitterController extends Zend_Controller_Action
{
	public function init()
	{

	}

	public function indexAction()
	{

	}

	public function authenticateAction()
	{

	}

	public function callbackAction()
	{

	}
}
</pre>
<p>Since we will need the config variables on <strong>all actions</strong>, we define it at init method:</p>
<pre class="brush: php; title: ; notranslate">
	public function init()
	{
		// Define zend config on registry. I'm doing it here, but you probably have this on your bootstrap
		$zendConfig = new Zend_Config_Ini( APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV );
		Zend_Registry::set( 'Zend_Config' , $zendConfig );
	}
</pre>
<p>We have to redirect user to Twitter.com, so that he can allow our application to access his account. This is done at authenticate action:</p>
<pre class="brush: php; title: ; notranslate">
	public function authenticateAction()
	{
		$zendConfig = Zend_Registry::get( 'Zend_Config' );

		// Instance oauth consumer with config options
		$consumer = new Zend_Oauth_Consumer($zendConfig-&gt;twitter-&gt;toArray());

		// Using the default session namespace, we store the request token serialized
		$session = new Zend_Session_Namespace();
		$session-&gt;requestToken = serialize( $consumer-&gt;getRequestToken() );

		// Redirect user to twitter.com
		$consumer-&gt;redirect();
	}
</pre>
<p>If user clicks on allow, he will be redirected to the callback action with a series of GET parameters containing the auth info. We have to process it in order to get the access token.</p>
<pre class="brush: php; title: ; notranslate">
	public function callbackAction()
	{
		$zendConfig = Zend_Registry::get( 'Zend_Config' );

		// Instance oauth consumer with config options
		$consumer = new Zend_Oauth_Consumer($zendConfig-&gt;twitter-&gt;toArray());

		// Use default session namespace
		$session = new Zend_Session_Namespace();

		// Check if we got a get request and that  user already have a request token
		if ( !empty( $this-&gt;_request-&gt;getQuery() ) &amp;&amp; !empty( $session-&gt;requestToken ) ) {

			// Get access token
			$token = $consumer-&gt;getAccessToken( $this-&gt;_request-&gt;getQuery() , unserialize( $session-&gt;requestToken ) );

			// Store access token on a session variable. You can also store on DB, in case you want to use later
			$session-&gt;accessToken = serialize( $token );

			// Remove request token, not necessary anymore
			unset( $session-&gt;requestToken );

			// Redirect to index action
			return $this-&gt;_helper-&gt;redirector( 'index' );
		} else {
			throw new Exception( 'Invalid access. No token provided.' );
		}
	}
</pre>
<p>As you can see, if everything works user is redirected to index action. At index action, i&#8217;ve placed an example of how to get user recent tweets. Zend_Service_Twitter offers many functions, you can check them at <a href="http://www.zendframework.com/manual/en/zend.service.twitter.html">ZF manual</a>.</p>
<pre class="brush: php; title: ; notranslate">
	public function indexAction()
	{
		// Default namespace
		$session = new Zend_Session_Namespace();

		try {
			// Check if user have access token.
			if ( empty( $session-&gt;accessToken ) ) {
				throw new Exception( 'You are not logged in. Please, try again.' );
			}

			// Unserialize access token
			$token = unserialize($session-&gt;accessToken);

			$zendConfig = Zend_Registry::get( 'Zend_Config' );

			// Prepare a config array with access token and config options
			$config = $zendConfig-&gt;twitter-&gt;toArray();
			$config['username'] = $token-&gt;getParam( 'screen_name' );
			$config['accessToken'] = $token;

			$twitter = new Zend_Service_Twitter( $config );

			// Verify if credentials work
			$response = $twitter-&gt;account-&gt;verifyCredentials();

			if ( !$response || !empty( $response-&gt;error ) ) {
				throw new Exception( 'Wrong credentials. Please, try to login again.' );
			}

			// Vardump user timeline ( one tweet )
			var_dump( $twitter-&gt;status-&gt;userTimeLine() );

		} catch ( Exception $e ) {

			echo $e-&gt;getMessage();
		}

		die();
	}
</pre>
<p>That&#8217;s it. Hope you found this tutorial userful.</p>
<p>If you want, you can download the full source-code: <a href="http://fernandomarcelo.com/code/TwitterController.phps">TwitterController.php</a>.</p>
<img src="http://feeds.feedburner.com/~r/FernandoMarcelo/~4/WiYVOLwrCDI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://fernandomarcelo.com/2010/09/using-zend_service_twitter-and-zend_oauth/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://fernandomarcelo.com/2010/09/using-zend_service_twitter-and-zend_oauth/</feedburner:origLink></item>
	</channel>
</rss><!-- Dynamic page generated in 0.283 seconds. --><!-- Cached page generated by WP-Super-Cache on 2012-05-17 22:03:30 -->

