<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Magentotuts&#039;s Blog</title>
	<atom:link href="http://magentotuts.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://magentotuts.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Mon, 15 Jun 2009 12:53:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='magentotuts.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Magentotuts&#039;s Blog</title>
		<link>http://magentotuts.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://magentotuts.wordpress.com/osd.xml" title="Magentotuts&#039;s Blog" />
	<atom:link rel='hub' href='http://magentotuts.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Implementing Hooks:</title>
		<link>http://magentotuts.wordpress.com/2009/06/15/implementing-hooks/</link>
		<comments>http://magentotuts.wordpress.com/2009/06/15/implementing-hooks/#comments</comments>
		<pubDate>Mon, 15 Jun 2009 12:53:30 +0000</pubDate>
		<dc:creator>magentotuts</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://magentotuts.wordpress.com/?p=230</guid>
		<description><![CDATA[Learning the operations of the different hooks available gives you the power to develop modules with drupal. In this tutorial we will be learning the operation of some basic and commonly used hooks. Inorder to operate on hooks we need to create a module which would use these hooks. Create a directory in sites/all/modules and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magentotuts.wordpress.com&amp;blog=7875464&amp;post=230&amp;subd=magentotuts&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Learning the operations of the different hooks available gives you the power to develop modules with drupal. In this tutorial we will be learning the operation of some basic and commonly used hooks. Inorder to operate on hooks we need to create a module which would use these hooks.</p>
<p>Create a directory in sites/all/modules and name it ‘mymodule’. This will be the directory of your new module and it should contain the .info and .module files.</p>
<p><strong>Creating the .info file:</strong></p>
<p>Before we start coding our new module, we need to create a simple text file that will hold some basic information about our module. Create a file in the ‘mymodule’ directory and call it mymodule.info. Enter the following contents into the file:</p>
<blockquote><p>; $Id$<br />
name = My module<br />
description = Just a test module to learn hooks<br />
core = 6.x</p></blockquote>
<p>You can add more into .info files. For more information on that go here : <a href="http://drupal.org/node/231036">http://drupal.org/node/231036</a>.</p>
<p><strong>Creating a .module file</strong>:</p>
<p>The .module file will hold all the code ie. All the hooks that the module implements goes in here. Create a ‘mymodule.module’ file in the mymodule directory. Now if you go to Administer-&gt; Site  Building -&gt; Modules you will be able to see your new module:</p>
<p>Now you can enable the module. However the module will not give any results because we haven’t implemented any hooks to join in with the Drupal workflow. In the following few sections we shall look at implementing some hooks.</p>
<p><strong>Hooks:</strong></p>
<p>For a complete list of hooks you can go to : <a href="http://api.drupal.org/api/group/hooks/6">http://api.drupal.org/api/group/hooks/6</a> and also <a href="http://drupal.org/files/drupal_6_core_hooks_cheat_sheet.pdf">http://drupal.org/files/drupal_6_core_hooks_cheat_sheet.pdf</a>.</p>
<p>We will be implementing only some of these hooks.</p>
<p><strong>Hook_perm:</strong></p>
<p>This hook is<strong> </strong>used to add user permissions into the permissions list. These permissions can then be selected on the user permissions page and used to restrict access to actions the module performs. Permissions are checked using user access().</p>
<p>Enter the following code in your .module file:</p>
<blockquote><p>&lt;?php<br />
function mymodule_perm() {<br />
return array(&#8216;permission 1&#8242;,&#8217;permission 2&#8242;);<br />
}</p></blockquote>
<p>This will add permissions to the permissions list. If you would go to Administer-&gt;User Management-&gt;Permissions you will see the following:</p>
<p style="text-align:center;"><img class="aligncenter size-full wp-image-232" title="permision" src="http://magentotuts.files.wordpress.com/2009/06/permision1.jpg?w=480&#038;h=58" alt="permision" width="480" height="58" /></p>
<p>You can check if the user has a permission by using user_access() function. (eg: if(user_access(‘permission 1’) {  //do something } )</p>
<p><strong>Hook_help:</strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p>The next hook is hook_help(), which allows you to create an entry in the global help page (/admin/help/) as well as providing help messages display at the top of pages. This hook accepts two parameters $path and $args. The return valu should be a string containing the help text. Here is an implementation:</p>
<blockquote><p>function mymodule_help($path) {<br />
switch ($path) {<br />
case &#8216;admin/help#mymodule&#8217;:<br />
return t(&#8216;This is a module being implemented primarily for understanding hooks !&#8217;);<br />
break;<br />
case &#8216;node/add/story&#8217;:<br />
return t(&#8216;Don\&#8217;t forget to:Enter a title, Promote to front page etc&#8217;);<br />
break;<br />
case &#8216;node/%/edit&#8217;:<br />
return t(&#8216;Some notes on editing nodes&#8217;);<br />
break;<br />
}}</p></blockquote>
<p>Now if you were to go to Administer-&gt;Help, you will see a link to My Module. This will give the following page:</p>
<p><img class="aligncenter size-full wp-image-233" title="helppage" src="http://magentotuts.files.wordpress.com/2009/06/helppage.jpg?w=480&#038;h=111" alt="helppage" width="480" height="111" /></p>
<p>Also if you try to create a new story by going to node/add/story you will see the help text on the top of the page as follows:</p>
<p><img class="aligncenter size-full wp-image-234" title="nodestory" src="http://magentotuts.files.wordpress.com/2009/06/nodestory.jpg?w=453&#038;h=156" alt="nodestory" width="453" height="156" /></p>
<p>Similiarly if you try editing any created content you will get a help text – ‘Some notes on editing nodes’ on the top of the page. So using hook_help we created can create a help page for the module and also add help texts to top of any page in drupal using $path.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/magentotuts.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/magentotuts.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/magentotuts.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/magentotuts.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/magentotuts.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/magentotuts.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/magentotuts.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/magentotuts.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/magentotuts.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/magentotuts.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/magentotuts.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/magentotuts.wordpress.com/230/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/magentotuts.wordpress.com/230/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/magentotuts.wordpress.com/230/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magentotuts.wordpress.com&amp;blog=7875464&amp;post=230&amp;subd=magentotuts&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://magentotuts.wordpress.com/2009/06/15/implementing-hooks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fc73ced983409690f072ce6902f4de64?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">magentotuts</media:title>
		</media:content>

		<media:content url="http://magentotuts.files.wordpress.com/2009/06/permision1.jpg" medium="image">
			<media:title type="html">permision</media:title>
		</media:content>

		<media:content url="http://magentotuts.files.wordpress.com/2009/06/helppage.jpg" medium="image">
			<media:title type="html">helppage</media:title>
		</media:content>

		<media:content url="http://magentotuts.files.wordpress.com/2009/06/nodestory.jpg" medium="image">
			<media:title type="html">nodestory</media:title>
		</media:content>
	</item>
		<item>
		<title>Understanding Hooks</title>
		<link>http://magentotuts.wordpress.com/2009/06/14/understanding-hooks/</link>
		<comments>http://magentotuts.wordpress.com/2009/06/14/understanding-hooks/#comments</comments>
		<pubDate>Sun, 14 Jun 2009 16:38:54 +0000</pubDate>
		<dc:creator>magentotuts</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://magentotuts.wordpress.com/?p=225</guid>
		<description><![CDATA[Hooks allow modules to interact with the Drupal core. In other words hooks allow modules to add their own stuff to Drupal’s workflow. To extend Drupal, a module need simply implement a hook. When Drupal wishes to allow intervention from modules, it determines which modules implement a hook and call that hook in all enabled [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magentotuts.wordpress.com&amp;blog=7875464&amp;post=225&amp;subd=magentotuts&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hooks allow modules to interact with the Drupal core. In other words hooks allow modules to add their own stuff to Drupal’s workflow. To extend Drupal, a module need simply implement a hook. When Drupal wishes to allow intervention from modules, it determines which modules implement a hook and call that hook in all enabled modules that implement it.</p>
<p><strong>Naming convention: </strong></p>
<p>The available hooks to implement are explained here in the Hooks section of the developer documentation : <a href="http://api.drupal.org/api/group/hooks/6">http://api.drupal.org/api/group/hooks/6</a>. Each hook has a defined set of parameters and a defined returned type. The string &#8220;hook&#8221; is used as a placeholder for the module name is the hook definitions. For example, if the module file is called example.module, then hook_help() as implemented by that module would be defined as example_help().</p>
<p><strong>How hooks work? :</strong></p>
<p>Drupal offers a system of callback hooks at various parts of the core code. The hooks are placed in key locations within the core code, such as when adding a user,publishing a blog etc&#8230; When the core code hits a hook, it will call out to all implementers of a given hook, finding implementers by looking for method names that adhere to the naming scheme.</p>
<p>For example <strong>hook_perm</strong> function is used to setup new permission types that can be granted to user account roles. If you go to the permissions page at drupal/?q=admin/user/permissions you will see a list of permissions.</p>
<p><img class="aligncenter size-full wp-image-227" title="permission" src="http://magentotuts.files.wordpress.com/2009/06/permission2.jpg?w=480&#038;h=261" alt="permission" width="480" height="261" /></p>
<p>Drupal checks for all the modules that implements the ‘hook_perm’ In this case blog and block module implement the hook_perm as blog_perm and block_perm respectively. Similarly all implementations of hook_perm are called to generate the final list. Thus modules adding permissions to the list by using hook_perm. Some modules like blogapi do not implement hook_perm, that’s why it is not present in the list.</p>
<p>So during the step by step process of executing a request Drupal executes hooks at certain points. While executing hooks Drupal finds functions in modules which implement that particular hook and executes those functions as well. Thus this way modules can intervene and add to the normal workflow of Drupal.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/magentotuts.wordpress.com/225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/magentotuts.wordpress.com/225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/magentotuts.wordpress.com/225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/magentotuts.wordpress.com/225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/magentotuts.wordpress.com/225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/magentotuts.wordpress.com/225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/magentotuts.wordpress.com/225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/magentotuts.wordpress.com/225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/magentotuts.wordpress.com/225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/magentotuts.wordpress.com/225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/magentotuts.wordpress.com/225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/magentotuts.wordpress.com/225/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/magentotuts.wordpress.com/225/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/magentotuts.wordpress.com/225/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magentotuts.wordpress.com&amp;blog=7875464&amp;post=225&amp;subd=magentotuts&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://magentotuts.wordpress.com/2009/06/14/understanding-hooks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fc73ced983409690f072ce6902f4de64?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">magentotuts</media:title>
		</media:content>

		<media:content url="http://magentotuts.files.wordpress.com/2009/06/permission2.jpg" medium="image">
			<media:title type="html">permission</media:title>
		</media:content>
	</item>
		<item>
		<title>Overriding with themes</title>
		<link>http://magentotuts.wordpress.com/2009/06/13/overriding-with-themes/</link>
		<comments>http://magentotuts.wordpress.com/2009/06/13/overriding-with-themes/#comments</comments>
		<pubDate>Sat, 13 Jun 2009 09:17:55 +0000</pubDate>
		<dc:creator>magentotuts</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://magentotuts.wordpress.com/?p=208</guid>
		<description><![CDATA[Drupal theming provides you with the ability to completely override the output that Drupal gives you by default and use your own custom markup instead. This tutorial will explain about making new themes to override the default theme functionality of Drupal. Create a new directory in the sites/all/themes folder. This is the place where all [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magentotuts.wordpress.com&amp;blog=7875464&amp;post=208&amp;subd=magentotuts&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Drupal theming provides you with the ability to completely override the output that Drupal gives you by default and use your own custom markup instead. This tutorial will explain about making new themes to override the default theme functionality of Drupal.</p>
<p>Create a new directory in the sites/all/themes folder. This is the place where all user defined themes should go. Name the new directory as &#8216;mytheme&#8217; which will be the new name of your theme.</p>
<p><strong>.info file:</strong></p>
<p>Create a .info file with the name mytheme.info. This file defines metadata for the theme, including the name of the theme, a description, its Drupal core version compatibility, and which theme engine it uses. Style sheets, JavaScripts, Block regions are also defined here. Enter the following contents now:</p>
<blockquote><p>; $Id$<br />
name = Mytheme<br />
description = Just a new theme.<br />
version = VERSION<br />
core = 6.x<br />
engine = phptemplate</p></blockquote>
<p>You will notice that at the top of files you download from Drupal. org there is always a line commented out that starts with $Id:, with a name and some date information that follows after. This is a special ID tag used by the version control system used by Drupal.org (CVS) to maintain all of the core and contributed code. Your custom files don’t need this line on them but it doesn’t hurt to have it there either. The empty version of this string is simply $Id$.</p>
<p>Now if you go to Administer-&gt;Site Building-&gt;Themes you will be able to see your new theme in the list. Now if you select this theme you will see a disorganized output. This is the default output from different modules. The main page is displayed by system/page.tpl.<br />
You can see this by using the Themer info function of the Devel module.</p>
<p>In order to organize the page output you need to override page.tpl (theme_page()). Lets copy the page.tpl file from bluemarine theme and paste it in our theme, then empty cache (using Devel), and reload the page. Now the page is organized into different regions. If you copy the style.css file also the the page would appear styled.</p>
<p><strong>Changing CSS:</strong></p>
<p>Let’s start by adding a border around content items to help them stand out on the page. Using Firebug in Firefox we can find out the exact element that styles the node, which is the .node at line 232 of the styles.css. Change it as follows:</p>
<blockquote><p>.node {<br />
margin: .5em 0 2em; /* LTR */<br />
border: 1px dashed #ccc;<br />
padding: .5em;<br />
}</p></blockquote>
<p>Your page will now appear with dashed lines around the nodes. You can also override other CSS files, but then you will have to include it in the .info file of the theme like this example : <code>stylesheets[all][] = system-menus.css.</code> <code> </code></p>
<p><strong>Modifying a Template file : (*.tpl.php files)<br />
</strong></p>
<p>Now let’s look at customizing the <em>page.tpl.php </em>file. This is the file that defines the general HTML structure of the entire page. The theme engine and enabled modules make a number of variables available to this file, and then these variables are simply output using PHP print statements. Let’s change the structure of our theme by moving the breadcrumb output up into the header region of the page.</p>
<p>Using the Themer info of Devel module you can find out how the breadcrumb is beign output. The parent file is page.tpl.php, so our breadcrumb is being printed from <em>page.tpl.php</em>. The function used to make the $breadcrumb variable is theme_breadcrumb().</p>
<p><img class="aligncenter size-full wp-image-213" title="breadcrumb" src="http://magentotuts.files.wordpress.com/2009/06/breadcrumb.jpg?w=405&#038;h=185" alt="breadcrumb" width="405" height="185" /></p>
<p>Open up the page.tpl.php file in your &#8216;mytheme&#8217; folder and go to about line 29, where the $header variable is printed. Down at line 42 is the $breadcrumb variable we want to move.</p>
<p>Now let’s modify the file to output the breadcrumbs immediately after the header, by removing line 42 and restoring it as a modification to line 30 as follows:</p>
<blockquote><p>&lt;tr&gt;<br />
&lt;td colspan=&#8221;2&#8243;&gt;&lt;div&gt;&lt;?php print $header ?&gt;<strong>&lt;?php print $breadcrumb ?&gt;</strong>&lt;/div&gt;&lt;/td&gt;<br />
&lt;/tr&gt;<br />
&lt;/table&gt;<br />
&lt;table border=&#8221;0&#8243; cellpadding=&#8221;0&#8243; cellspacing=&#8221;0&#8243; id=&#8221;content&#8221;&gt;</p></blockquote>
<p>In a similiar way you can change the appearance of other items like node,block.. using node.tpl.php,block.tpl.php.</p>
<p><strong>Template.php:</strong></p>
<p>The last, crucial piece of Drupal theming is the ability to completely override the output that Drupal gives you by default and use your own custom markup instead. You may find that while the template files give you a lot of control, you can’t really do much about the HTML that you are given inside those variables (like $header,$breadcrumbs). You can do all the HTML editing around them that you want, but how do you crack into the variables themselves. This is where template.php comes into picture. Using template.php file we can override or add variables and also override theme functions.</p>
<p><strong>Overriding/Adding Variables:</strong></p>
<p>All variables that go out to a template file are first passed through a special kind of function, called a preprocess function. You can add your own preprocess function to your <em>template.php </em>file and get the last shot at the variables before they head out to the template. To keep things tidy, you can use one preprocess function per template; for example, you can create a mytheme_preprocess_page function to affect variables to be used in your <em>page.tpl.php </em>file. With this function, you can define, or redefine, any variable.</p>
<p>For example you can define a variable called $random_number as follows:</p>
<blockquote><p>function mytheme_preprocess_page(&amp;$vars) {<br />
$vars['random_number'] = rand(1, 100);<br />
}</p></blockquote>
<p>Then (after clearing the Drupal cache), you can print out that variable out in your<em> page.tpl.php </em>file just like any other variable:</p>
<blockquote><p>&lt;?php print $random_number; ?&gt;</p></blockquote>
<p>You use the exact same procedure to override an existing variable. When you assign a variable name that is the same as the one Drupal is already using, yours will take precedence.For example to change $submitted from &#8216;Submitted by&#8230;&#8217; to &#8216;Posted on&#8230;&#8217; :</p>
<blockquote><p>function mytheme_preprocess_node(&amp;$vars) {<br />
$vars['submitted'] = t(&#8216;Posted on &#8216;) .format_date($vars['node']-&gt;created, &#8216;custom&#8217;, &#8216;F j, Y&#8217;);<br />
}</p></blockquote>
<p>Here is documentation listing all variables available in <a href="http://drupal.org/node/11812">page.tpl.php</a>, <a href="http://drupal.org/node/11816">node.tpl.php</a>, and <a href="http://drupal.org/node/11813">block.tpl.php</a>.</p>
<p><strong>Overriding Theme functions:</strong></p>
<p>Much of Drupal’s HTML output is easily accessible in template files. But what about something like the page’s “breadcrumb trail,” which shows the hierarchy to the current page? Unfortunately, there’s no <em>breadcrumb.tpl.php </em>file. In this situation, you need todig a little bit deeper, to the place where remaining markup in Drupal is initially defined:<em> theme functions</em>.</p>
<p>Theme functions are regular PHP functions located in Drupal’s code whose names begin with theme_. Every element on the page that is not in a template file is run through a theme function, such as the theme_breadcrumb() function: (theme.inc)</p>
<p>The function basically just takes an array of HTML links and uses PHP’s implode() function to concatenate the values using the » character, wrapping this in a &lt;div&gt; with the class of “breadcrumb.”</p>
<blockquote><p>function theme_breadcrumb($breadcrumb) {<br />
if (!empty($breadcrumb)) {<br />
return &#8216;&lt;div&gt;&#8217;. implode(&#8216; » &#8216;, $breadcrumb) .&#8217;&lt;/div&gt;&#8217;;<br />
}}</p></blockquote>
<p>In its current state, this function will print out the breadcrumb trail on a page, such as Home » Administer » Site building » Themes. But what if we decide that we’d rather the breadcrumb be printed as Home::Administer::Site building::Themes, with doublecolons instead? No problem! We’ll just pop open <em>theme.inc </em>and change it there, right? Wrong! The proper way to handle overriding theme functions is by simply copying the function into your <em>template.php </em>file and naming it according to Drupal’s naming conventions so that it’s recognized. Then you can modify it however you like.</p>
<blockquote><p>function mytheme_breadcrumb($breadcrumb) {<br />
if (!empty($breadcrumb)) {<br />
return<strong> &#8216;&lt;div&gt;&#8217;. implode(&#8216; :: &#8216;, $breadcrumb) .&#8217;&lt;/div&gt;&#8217;;</strong><br />
}}</p></blockquote>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/magentotuts.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/magentotuts.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/magentotuts.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/magentotuts.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/magentotuts.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/magentotuts.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/magentotuts.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/magentotuts.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/magentotuts.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/magentotuts.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/magentotuts.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/magentotuts.wordpress.com/208/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/magentotuts.wordpress.com/208/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/magentotuts.wordpress.com/208/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magentotuts.wordpress.com&amp;blog=7875464&amp;post=208&amp;subd=magentotuts&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://magentotuts.wordpress.com/2009/06/13/overriding-with-themes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fc73ced983409690f072ce6902f4de64?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">magentotuts</media:title>
		</media:content>

		<media:content url="http://magentotuts.files.wordpress.com/2009/06/breadcrumb.jpg" medium="image">
			<media:title type="html">breadcrumb</media:title>
		</media:content>
	</item>
		<item>
		<title>Theme</title>
		<link>http://magentotuts.wordpress.com/2009/06/13/theme/</link>
		<comments>http://magentotuts.wordpress.com/2009/06/13/theme/#comments</comments>
		<pubDate>Sat, 13 Jun 2009 07:18:01 +0000</pubDate>
		<dc:creator>magentotuts</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://magentotuts.wordpress.com/?p=190</guid>
		<description><![CDATA[Drupal uses default theme files in modules for producing output. For example if you check out drupal\modules\system you can see some template files like page.tpl,box.tpl etc. All these template files, CSS, JavaScript, images, and HTML can be overridden by a Drupal theme. Modules generate the contents of a given page, and the theme system provides [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magentotuts.wordpress.com&amp;blog=7875464&amp;post=190&amp;subd=magentotuts&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Drupal uses default theme files in modules for producing output. For example if you check out drupal\modules\system you can see some template files like page.tpl,box.tpl etc. All these template files, CSS, JavaScript, images, and HTML can be overridden by a Drupal theme. Modules generate the contents of a given page, and the theme system provides the opportunity to cut in and customize the page before it’s displayed.</p>
<p><strong>The Theme System :</strong></p>
<p><strong><img class="aligncenter size-full wp-image-191" title="themsys" src="http://magentotuts.files.wordpress.com/2009/06/themsys.jpg?w=388&#038;h=424" alt="themsys" width="388" height="424" /></strong></p>
<p>Each path in Drupal corresponds to a particular module that is responsible for handling the page request. For example, “node/1” is handled by the Node module, “admin/build/themes” is handled by the System module. Once the module has built up the contents of the page, it calls up the theme system with a special function called theme().</p>
<p><strong>The theme() function:</strong></p>
<p>Theme functions are never called directly. They are instead called through a function called theme(). So even though a module may define a function such as theme_username(), when the module needs to output its code, it would call theme(&#8216;username&#8217;) instead. The theme() function is what makes this system of overrides possible. For eg: if theme_breadcrumb() function (present in includes/ themes.inc) has not been overridden then it is called else the overriding function(which would be present in template.php of theme) would be called.</p>
<p><strong>What files constitute a theme ?</strong></p>
<p>Themes are present in the drupal/themes directory. Drupal provides a no of themes like bluemarine, garland, chameleon etc..Some of these uses PHPtemplate engine like bluemarine, garland (*.tpl.php files) while others like chameleon dont use template engines. Using PHPTemplate engine we can create .tpl files (uses HTML and PHP) to override theme functions. For eg: to override theme_page() we can make a file called page.tpl.php. However themes that do not use the PHPtemplate engine, have to uses a .theme files which is pure php and contains overriding functions. (chameleon_page(),chameleon_node()..).</p>
<p>Themes also contain CSS,javascript,images which integrate with the template files to produce the desired output. Lets check out the contents of the bluemarine theme :</p>
<p><img class="aligncenter size-full wp-image-200" title="bluemarine" src="http://magentotuts.files.wordpress.com/2009/06/bluemarine.jpg?w=400&#038;h=304" alt="bluemarine" width="400" height="304" /></p>
<p><strong>themename.info (bluemarine.info): </strong></p>
<p>This file defines a variety of metadata for the theme, including the name of the theme, a description, its Drupal core version compatibility, and which theme engine it uses. Beyond those basics, the <em>.info </em>file can also define the block regions available to the theme, and the CSS stylesheets and JavaScript files used.</p>
<p><strong>Template files (page.tpl,block.tpl..):</strong></p>
<p>With these files, using Drupal’s PHPTemplate file naming convention, you are able to ‘override’ the default theme function. Each one controls the layout of certain parts of the template. To edit the display of blocks, nodes, and comments, edit the <tt>block.tpl.php</tt>, node.tpl.php and comment.tpl.php files respectively. The content generated by these files is used in page.tpl.php.</p>
<p>These files are overriding the default files. All you have to do is find the default template file, copy it into your theme folder, and edit it. Many themes start with these main Drupal core default templates:</p>
<p><em>page.tpl.php (located in modules/system)</em>: Controls the layout of the entire page. This isn’t for the page content type; you can think of it more as the overall screen in which your content types and blocks are displayed.</p>
<p><em>node.tpl.php (located in modules/node)</em>: This is used for the display of each individual node.</p>
<p><em>block.tpl.php (located in modules/system)</em>: This is used for all of the blocks on the site.</p>
<p><em>comment.tpl.php (located in modules/comment)</em>: Each individual comment is displayed with this file.</p>
<p><em>box.tpl.php (located in modules/system)</em>: For the container element that surrounds search results and that surrounds a list of comments that is attached to a node.</p>
<p>You can find any other templates in the folder of the module that created it. for example, forum templates will be in the forum module folder (<em>modules/forum</em>). For a list of these : <a href="http://drupal.org/node/190815">http://drupal.org/node/190815</a>.</p>
<p><strong>Images and CSS : </strong></p>
<p>Stylesheets can be used along with templates to create the desired look. The theme uses styles.css which is included by default. Also other stylesheets can be used but then you must declare it in the .info file. Images include the logo (logo.png) and the screenshot (screenshot.png).</p>
<p><strong>Template.php : </strong></p>
<p>This file can be seen in garland theme. This file can be used to override theme functions (those present in theme.inc). For example we can change the appearance of the breadcrumb by overriding the theme_breadcrumb() function.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/magentotuts.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/magentotuts.wordpress.com/190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/magentotuts.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/magentotuts.wordpress.com/190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/magentotuts.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/magentotuts.wordpress.com/190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/magentotuts.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/magentotuts.wordpress.com/190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/magentotuts.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/magentotuts.wordpress.com/190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/magentotuts.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/magentotuts.wordpress.com/190/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/magentotuts.wordpress.com/190/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/magentotuts.wordpress.com/190/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magentotuts.wordpress.com&amp;blog=7875464&amp;post=190&amp;subd=magentotuts&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://magentotuts.wordpress.com/2009/06/13/theme/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fc73ced983409690f072ce6902f4de64?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">magentotuts</media:title>
		</media:content>

		<media:content url="http://magentotuts.files.wordpress.com/2009/06/themsys.jpg" medium="image">
			<media:title type="html">themsys</media:title>
		</media:content>

		<media:content url="http://magentotuts.files.wordpress.com/2009/06/bluemarine.jpg" medium="image">
			<media:title type="html">bluemarine</media:title>
		</media:content>
	</item>
		<item>
		<title>Important Modules</title>
		<link>http://magentotuts.wordpress.com/2009/06/12/important-modules/</link>
		<comments>http://magentotuts.wordpress.com/2009/06/12/important-modules/#comments</comments>
		<pubDate>Fri, 12 Jun 2009 04:17:56 +0000</pubDate>
		<dc:creator>magentotuts</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://magentotuts.wordpress.com/?p=179</guid>
		<description><![CDATA[Drupal ships with a lot of necessary modules like Blog, Forum, Taxonomy, Poll, Locale …They do most necessary tasks when building a website. But there are also some frequently used contributed modules that gives added functionality and power to Drupal. Some examples include CCK, Views, Devel etc.. Devel Module: Devel is one of the most [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magentotuts.wordpress.com&amp;blog=7875464&amp;post=179&amp;subd=magentotuts&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Drupal ships with a lot of necessary modules like Blog, Forum, Taxonomy, Poll, Locale …They do most necessary tasks when building a website. But there are also some frequently used contributed modules that gives added functionality and power to Drupal. Some examples include CCK, Views, Devel etc..</p>
<p><strong>Devel Module:</strong></p>
<p>Devel is one of the most useful tools for Drupal Developers and Themers alike. Devel allows you to: print database queries for each rendered page, expose some handy functions for printing complex arrays in a human-readable fashion, empty cache, rebuild menus with one click, generate dummy content (nodes, users, comments) – great for theming and testing views, Theme Developer: allows you to click any rendered element; observe which function created it; offers candidate override function and displays available arguments as well as candidate template files. You can download it here : <a href="http://drupal.org/project/devel">http://drupal.org/project/devel</a>.</p>
<p><img class="aligncenter size-full wp-image-186" title="devel" src="http://magentotuts.files.wordpress.com/2009/06/devel.jpg?w=202&#038;h=354" alt="devel" width="202" height="354" /></p>
<p><strong>Content Construction Kit (CCK):</strong></p>
<p>As the name suggest this module is used to build custom content types.<strong> </strong>Drupal’s  gives each one of the new content types only a “Title” and “Body” field. We’ll need quite a few more fields. With CCK you can add custom field to content types. So you can create forms<br />
containing a variety of fields—such as checkboxes, select lists, image uploads, and many others. You can download the CCK module here: <a href="http://drupal.org/project/cck">http://drupal.org/project/cck</a>.</p>
<p><img class="aligncenter size-full wp-image-187" title="cck" src="http://magentotuts.files.wordpress.com/2009/06/cck.jpg?w=480&#038;h=188" alt="cck" width="480" height="188" /></p>
<p><strong>Views Module:</strong></p>
<p>The Views module is the natural counterpart to CCK. Views allows you to create pages and blocks that pull data back out and display it to your visitors. For nearly any purpose of displaying content, the Views module can provide a listing of content in a variety of ways: a table, a list of full nodes or teasers, an RSS feed, a list of individual fields, and more.  The views project page on Drupal.org describes Views as: a smart query builder that, given enough information, can build the proper query, execute it, and display the results.<br />
To sum it up, Views gives you a very usable interface to create complex MySQL queries which are used to display your content. You can download the Views module here : <a href="http://drupal.org/project/views">http://drupal.org/project/views</a>.</p>
<p><strong>FCKeditor and IMCE:</strong></p>
<p>One of the biggest criticisms of Drupal, apart from the fact that it does not come with a WYSIWYG editor built in, is that it has no built-in image handling. Out of the box, Drupal’s built-in Upload module allows anyone with “upload files” permissions to attach image files to content they create. It’s then possible for them to manually insert &lt;img&gt; tags linking those image files into the content they’re writing. However, that’s a pretty cumbersome process for many users, especially those attaching many images to a long post, like a magazine article. FCKeditor is a WYSIWYG editor that allows people without HTML knowledge to create rich website content. IMCE is an add-on module that can work with editors such as FCKEditor to make it easy to add images to website content. To download FCKeditor : <a href="http://drupal.org/project/fckeditor">http://drupal.org/project/fckeditor</a>. To download IMCE: <a href="http://drupal.org/project/imce">http://drupal.org/project/imce</a>.</p>
<p><strong><img class="aligncenter size-full wp-image-188" title="fckeditor" src="http://magentotuts.files.wordpress.com/2009/06/fckeditor.jpg?w=480&#038;h=427" alt="fckeditor" width="480" height="427" /><br />
</strong></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/magentotuts.wordpress.com/179/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/magentotuts.wordpress.com/179/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/magentotuts.wordpress.com/179/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/magentotuts.wordpress.com/179/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/magentotuts.wordpress.com/179/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/magentotuts.wordpress.com/179/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/magentotuts.wordpress.com/179/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/magentotuts.wordpress.com/179/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/magentotuts.wordpress.com/179/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/magentotuts.wordpress.com/179/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/magentotuts.wordpress.com/179/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/magentotuts.wordpress.com/179/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/magentotuts.wordpress.com/179/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/magentotuts.wordpress.com/179/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magentotuts.wordpress.com&amp;blog=7875464&amp;post=179&amp;subd=magentotuts&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://magentotuts.wordpress.com/2009/06/12/important-modules/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fc73ced983409690f072ce6902f4de64?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">magentotuts</media:title>
		</media:content>

		<media:content url="http://magentotuts.files.wordpress.com/2009/06/devel.jpg" medium="image">
			<media:title type="html">devel</media:title>
		</media:content>

		<media:content url="http://magentotuts.files.wordpress.com/2009/06/cck.jpg" medium="image">
			<media:title type="html">cck</media:title>
		</media:content>

		<media:content url="http://magentotuts.files.wordpress.com/2009/06/fckeditor.jpg" medium="image">
			<media:title type="html">fckeditor</media:title>
		</media:content>
	</item>
		<item>
		<title>Drupal Introduction</title>
		<link>http://magentotuts.wordpress.com/2009/06/10/drupal-introduction/</link>
		<comments>http://magentotuts.wordpress.com/2009/06/10/drupal-introduction/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 19:22:51 +0000</pubDate>
		<dc:creator>magentotuts</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://magentotuts.wordpress.com/2009/06/10/drupal-introduction/</guid>
		<description><![CDATA[Drupal can be regarded as &#8220;content management system&#8221; (CMS) however it is also a &#8220;content management framework&#8221; (CMF). In other words, unlike a typical CMS, it is geared more towards configurability and customization.In addition to providing sitebuilding tools, it offers ways for programmers and developers to customize Drupal using plug-in modules.a sort of “builder’s kit” [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magentotuts.wordpress.com&amp;blog=7875464&amp;post=171&amp;subd=magentotuts&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Drupal can be regarded as &#8220;content management system&#8221; (CMS) however it is also a &#8220;content management framework&#8221;<br />
(CMF). In other words, unlike a typical CMS, it is geared more towards configurability and customization.In addition<br />
to providing sitebuilding tools, it offers ways for programmers and developers to customize Drupal using plug-in<br />
modules.a sort of “builder’s kit” made up of pre-designed components that can be used as-is or can be extensively<br />
reconfigured to suit your needs.Drupal’s power comes from its more abstracted approach to handling web content and<br />
functionality.</p>
<p>Some of the important features :</p>
<p>Flexible module system<br />
Modules are plug-ins that can modify and add features to a Drupal site. For almost<br />
any functional need, chances are good that either an existing module fits the need<br />
exactly or can be combined with other modules to fit the need.</p>
<p>Customizable theming system<br />
All output in Drupal is fully customizable, so you can bend the look and feel of<br />
your site to your will.</p>
<p>Extensible content creation<br />
You can define new types of content (blog, event, word of the day) on the fly.<br />
Contributed modules can take this one step further and allow administrators to<br />
create custom fields within your newly created content types.</p>
<p>Search engine optimization<br />
Drupal offers out-of-the-box support for human-readable system URLs, and all of<br />
Drupal’s output is standards-compliant; both of these features make for searchengine<br />
friendly websites.</p>
<p>Role-based access permissions<br />
Custom roles and a plethora of permissions allow for fine-grained control over who<br />
can access what within the system. And existing modules can take this level of<br />
access control even further—down to the individual user level.</p>
<p>Social publishing and collaboration tools<br />
Drupal has built-in support for tools such as group blogging, comments, forums,<br />
and customized user profiles. The addition of almost any other feature you can<br />
imagine—for instance, ratings, user groups, or moderation tools—is only a download<br />
away.</p>
<p>Modules:</p>
<p>All of the administrative and user functionality in Drupal, from fundamental<br />
features such as ability to log in or create content to complex functions,all come from modules<br />
In Drupal each module provides specific functionality, and works together with other<br />
modules to enhance their functionality.Some examples of modules are the Contact module, which enables a site-wide</p>
<p>contact form, and the User module, which handles user authentication and permission checking.<br />
The &#8220;core&#8221; drupal modules are present in the drupal/modules folder while the &#8220;contributed&#8221; modules should be placed</p>
<p>in drupal/sites/all/modules. You can enable or disable modules by going to Administer-&gt;SiteBuilding-&gt;Modules.</p>
<p><img class="aligncenter size-full wp-image-174" title="modul" src="http://magentotuts.files.wordpress.com/2009/06/modul.jpg?w=480&#038;h=272" alt="modul" width="480" height="272" /></p>
<p>Users:</p>
<p>The next building block of a Drupal website is the concept of users.The first user you create when you build a new</p>
<p>Drupal site is special.User 1 has permission to perform any action on the Drupal site.Every additional user can be</p>
<p>assigned to configurable roles. Each role can be given permissions to do different things on the<br />
website: visiting specific URLs, viewing particular kinds of content, posting comments etc.. By default, Drupal</p>
<p>comes with two predefined roles: authenticated user and anonymous user. Anyone who creates a user account on the</p>
<p>site is automatically assigned the “authenticated user” role, and any visitors who haven’t yet created<br />
user accounts (or haven’t yet logged in with their username and password) have the “anonymous user” role.</p>
<p><img class="aligncenter size-full wp-image-175" title="permission" src="http://magentotuts.files.wordpress.com/2009/06/permission.jpg?w=480&#038;h=344" alt="permission" width="480" height="344" /></p>
<p>Nodes:</p>
<p>Any form of content such as blog post,pages,news items are all stored as nodes.All nodes, regardless of the type of</p>
<p>content they store, share a handful of basic properties such as: author,creation date,title,body. In addition to</p>
<p>nodes’ basic, common properties, all nodes can take advantage of certain<br />
built-in Drupal features, like flags that indicate whether they’re published or unpublished<br />
and settings to control how each type of node is displayed. Permissions to create<br />
and edit each type of node can also be assigned to different user roles; for example,<br />
users with the “blogger” role could create “Blog entry” nodes, but only “administrator”<br />
or “editor” users could create “News” nodes. Drupal comes preconfigured with two types of nodes: “Page” and “Story.”</p>
<p>You can also create your own content types.What happens, though, if you need to store more information than “title”</p>
<p>and “body content?” Plug-in modules can add to Drupal’s content system new kinds of nodes that offer more<br />
features. One example (which comes with Drupal) is the “Poll” module. When users<br />
create new “Poll” nodes, they create a list of poll questions rather than the usual “body”<br />
content.The idea that new modules add properties and build on top of the node system means<br />
that all content in Drupal is built on the same underlying framework.. Features like searching, rating,<br />
and comments all become plug-and-play components for any new type of node you may define, because<br />
under the hood, Drupal knows how to interface with their base elements—nodes.</p>
<p>Taxonomy:</p>
<p>Drupal maintains almost everything as a node. So How do you break your separeate your node into separate categories</p>
<p>?.That’s exactly what Taxonomy does.It allows the administrator of a site to set up categories of topics that nodes</p>
<p>can be associated with when they’re created. So you can create predefined “Tags” for bloggers to enter manually when</p>
<p>they post. The Taxonomy module calls all of these things “terms,” and provides a page for each descriptive term</p>
<p>that’s used on the site. When a visitor views one of these pages, Drupal pulls up a list of<br />
all the nodes that were tagged with the term.</p>
<p>Comments:</p>
<p>Comments are merely responses by a user to a piece of content, and exist only in relation<br />
to that content. Like nodes, but to a lesser extent, comments can be expanded with contributed modules to have</p>
<p>additional features such as ratings or file upload fields. An important point to note is that comments are not</p>
<p>stored as nodes, they are only attached to nodes.</p>
<p>Blocks:</p>
<p>Block are widgets that fit into areas such as the sidebars, footers, and headers of a<br />
Drupal site. They’re generally used to display helpful links or dynamic lists such as<br />
“Most popular content” or “Latest comments” and similar items. By going to Administer-&gt;Site Building-&gt;Blocks<br />
you can configure blocks to show up on certain regions,or to be hidden.</p>
<p><img class="aligncenter size-full wp-image-177" title="blocks" src="http://magentotuts.files.wordpress.com/2009/06/blocks.jpg?w=480&#038;h=397" alt="blocks" width="480" height="397" /></p>
<p>Menus:</p>
<p>Menus hold the navigation links to various web pages on a Drupal site. Drupal comes with three default</p>
<p>menus.Navigation The main system menu. In practice, this menu is the default “dumping ground” of<br />
links offered by modules, including administrative tasks.<br />
Primary links An empty menu provided for custom navigation needs, typically displayed very<br />
prominently in the site’s design. Major sections of the site such as “Home” and<br />
“Blog” tend to be placed in the Primary links menu.<br />
Secondary links Another empty menu provided for custom navigation needs, but more subdued in<br />
presentation. As a general rule, more supplementary pages such as “Terms of Service”<br />
or “FAQ” are placed in the Secondary links menu.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/magentotuts.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/magentotuts.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/magentotuts.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/magentotuts.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/magentotuts.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/magentotuts.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/magentotuts.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/magentotuts.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/magentotuts.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/magentotuts.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/magentotuts.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/magentotuts.wordpress.com/171/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/magentotuts.wordpress.com/171/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/magentotuts.wordpress.com/171/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magentotuts.wordpress.com&amp;blog=7875464&amp;post=171&amp;subd=magentotuts&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://magentotuts.wordpress.com/2009/06/10/drupal-introduction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fc73ced983409690f072ce6902f4de64?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">magentotuts</media:title>
		</media:content>

		<media:content url="http://magentotuts.files.wordpress.com/2009/06/modul.jpg" medium="image">
			<media:title type="html">modul</media:title>
		</media:content>

		<media:content url="http://magentotuts.files.wordpress.com/2009/06/permission.jpg" medium="image">
			<media:title type="html">permission</media:title>
		</media:content>

		<media:content url="http://magentotuts.files.wordpress.com/2009/06/blocks.jpg" medium="image">
			<media:title type="html">blocks</media:title>
		</media:content>
	</item>
		<item>
		<title>Database Concepts</title>
		<link>http://magentotuts.wordpress.com/2009/06/01/database-concepts/</link>
		<comments>http://magentotuts.wordpress.com/2009/06/01/database-concepts/#comments</comments>
		<pubDate>Mon, 01 Jun 2009 05:16:10 +0000</pubDate>
		<dc:creator>magentotuts</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://magentotuts.wordpress.com/?p=142</guid>
		<description><![CDATA[Retrieving database information in Magento can be a bit complicated. Technically it is possible to write raw SQL statements to load entities and all their associated attribute values. However due to the EAV database design it is difficult to write query statements to get exactly what you want. Utilizing an EAV modeling pattern allows for [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magentotuts.wordpress.com&amp;blog=7875464&amp;post=142&amp;subd=magentotuts&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Retrieving database information in Magento can be a bit complicated. Technically it is possible to write raw SQL statements to load entities and all their associated attribute values. However due to the EAV database design it is difficult to write query statements to get exactly what you want. Utilizing an EAV modeling pattern allows for unlimited attributes on any product, category, customer, or order, but EAV also depletes a programmer’s ability to write queries against the data.</p>
<p><strong>SQL query example:</strong></p>
<p>Lets look at an example of an SQL statement which gets all the products (product_id) in a  particular category:</p>
<blockquote><p>$sql = &#8220;SELECT product_id  FROM catalog_category_product WHERE category_id=3&#8243;;<br />
$data = Mage::getSingleton(&#8216;core/resource&#8217;) -&gt;getConnection(&#8216;core_read&#8217;)-&gt;fetchAll($sql);</p></blockquote>
<p>You will get the product ids as an array in $data. However if we wanted to get all the attributes of a product based on the product_id then it is difficult as all the product info is not present in one table. Due to the EAV design it is loosely present in many tables. So we require to join a number of tables to get the product information. In such cases we should try using Magento’s built-in query methods instead of directly running queries on the database. More on built in query methods later.</p>
<p><strong>Analyzing the code:</strong></p>
<p>Lets analyze the code:</p>
<p>$data = Mage::getSingleton(&#8216;core/resource&#8217;);</p>
<p>First of all we require a connection to the database to perform queries. This is done by using resources. The role of a ‘resource’<em> </em>in Magento is to manage database connections. So using getSingleton(‘core/resource’) we get an instance of Mage_Core_Model_Resource.</p>
<p>Check out that file and you will see a function called getConnection($name). This is used to get a ‘read’ or ‘write’ connection (‘core_read’ – read connection, ‘core_write’ – write connection).</p>
<p>The fetchAll function executes the query and returns all the rows to $data. The results are returned as an array of results (array of arrays).</p>
<p><strong>How do i know the table names ?</strong></p>
<p>You can see Magento&#8217;s database design by checking this link <a href="http://www.magentocommerce.com/wiki/development/magento_database_diagram">http://www.magentocommerce.com/wiki/development/magento_database_diagram.</a></p>
<p>The core ResourceModel has a method called getTable() to get the table name of any model in the system. Table names do not have to follow the name of the model, an end-user can change the table names by changing an XML setting.Therefore, it is best to use the getTable method of the core resource.</p>
<p>$res = Mage::getSingleton(’core/resource’)-&gt;getConnection(’core_read’);<br />
$tableName = $res-&gt;getTable(’catalog/product’);</p>
<p>This will give $tableName as ’catalog_product_entity’. This happens because we have the following XML configuration in the <em>catalog </em>module’s config file.</p>
<blockquote><p>&lt;global&gt;<br />
&lt;models&gt;<br />
&lt;catalog&gt;<br />
&lt;class&gt;Mage_Catalog_Model&lt;/class&gt;<br />
&lt;resourceModel&gt;catalog_resource_eav_mysql4&lt;/resourceModel&gt;<br />
&lt;/catalog&gt;</p></blockquote>
<blockquote><p>&lt;catalog_resource_eav_mysql4&gt;<br />
&lt;class&gt;Mage_Catalog_Model_Resource_Eav_Mysql4&lt;/class&gt;<br />
&lt;entities&gt;<br />
&lt;product&gt;<br />
&lt;table&gt;<strong>catalog_product_entity</strong>&lt;/table&gt;<br />
&lt;/product&gt;</p></blockquote>
<p><strong>ResourceModels:</strong></p>
<p>ResourceModels manage the different read/write connections and automatically figure out table names based on convention and perform the database related operations for a particular Model. ie. It acts as an abstraction to retrieve (or write) data from database. For eg: in the Mage_Catalog_Model_Product class you can see that to get data it uses the getResource() function. This function gets the ResourceModel to perform the required database operation.</p>
<p>For the Catalog Module the ResourceModels can be found in Catalog\Model\Resource\Eav\Mysql4 directory. (this is defined in the config.xml – search for &lt;resourceModels&gt;). For getting ResourceModels we use the getResourceModel() method.</p>
<p>Mage::getResourceModel(‘catalog/product’) will create an instance of  Mage_Catalog_Model_Resource_Eav_Mysql4_Product.php. (If class names have the term Mysql4 in their names, they are generally called ResourceModels. If the word Entity appears in the class name, then the resource is an EAV Entity). You will get the same result by calling Mage::getModel(‘catalog/resource_eav_mysql4_product&#8217;) also.</p>
<p>Now take a look at this Product.php file. You will see some sql statements like the one below:</p>
<blockquote><p>public function getIdBySku($sku)<br />
{return $this-&gt;_read-&gt;fetchOne(&#8216;select entity_id from &#8216;.$this-&gt;getEntityTable().&#8217; where sku=?&#8217;, $sku);}</p></blockquote>
<p>So if we need to get the product id for a sku value then we can simply do it by:</p>
<blockquote><p>$id = Mage::getResourceModel(&#8216;catalog/product&#8217;)-&gt;getIdBysku(5);</p></blockquote>
<p>Its easier to use predefined functions than write your own query statements. Similiarly there are other funtions predefined in the Resource Models that you can use to retrieve data from database.</p>
<p><strong>Entities:</strong></p>
<p>Entities extend Magento’s resource objects. Basically, Entities pair up to selected Models and help them save to the database. Entities behave mostly like resource models, as they are just a special sub-class of resources. Entities for catalog module are in Mage\Catalog\Model\Entity.</p>
<p><strong>Collections:</strong></p>
<p>Entities are designed to load one item, or <em>record</em>, at a time. But, most of the time when we think of database queries we want to write a SELECT statement that gives use a result with multiple rows. The entity models are not able to do that.</p>
<p>What if we want to select all records from the database matching some criteria. Normally, a simple SELECT statement with a WHERE clause would work. But, things are not that simple because of the EAV design. Not all of the data that makes up an entity lives in one table, so we need to JOIN more tables. To properly construct a WHERE clause we would have to know exactly which tables our specific data is stored in. This is the problem that <em>collections </em>solve. Loading an arbitrary number of records based on criteria is the job of entity <em>collection</em>.</p>
<p>Probably the most useful method of a collection is the <em>addAttributeToFilter</em> method. This method takes an attribute code and a condition.</p>
<blockquote><p>$products = Mage::getModel(’catalog/product’)-&gt;getCollection();<br />
$products-&gt;addAttributeToFilter(’sku’, ’9999’);<br />
$products-&gt;load();</p></blockquote>
<p>In the above example, the condition is a simple string, but the condition can also be an array. When passing a condition array, the key of the array designates the type of comparison. The type can be eq, for equals, like for like comparisons, gt for a greater than comparison. Here is the same example above, but searching for an array of product IDs.</p>
<blockquote><p>$products = Mage::getModel(’catalog/product’)-&gt;getCollection();<br />
$products-&gt;addAttributeToFilter(’entity_id’, array(’in’=&gt; array(1,2,36,35) ));<br />
$products-&gt;load();</p></blockquote>
<blockquote><p><em>//runs the query<br />
</em><em>SELECT  * FROM ‘catalog_product_entity‘ WHERE  (e.entity_id in (1, 2, 36, 35))<br />
*/</em></p></blockquote>
<p>For loading selected attribute values , we can use the addAttributeToSelect method.</p>
<p>This is only scratching the surface of the SQL that you can generate with collections. Look at the Eav/Model/Entity/Collection/Abstract.php file for a full list of methods to manipulate your SQL. Remember that collections are the only way to load entity objects if you need to use a WHERE clause other than querying against the table’s primary key field. When dealing with non-entity models, you can always write raw SQL and run it against a resource connection.</p>
<p><strong>Using Zend to prepare statements:</strong></p>
<p>You may have noticed that in the ResourceModel files magento team does not use plain SQL.  Instead they prepare it using Zend_Db This means that Magento is using Zend for handling requests.</p>
<p>$read = Mage::getSingleton(’core/resource’)-&gt;getConnection(’core_read’);<br />
echo get_class($read);</p>
<p>You will get the class as Varien_Db_Adapter_Pdo_Mysql which is an extension of Zend_Db_Adapter Abstract. You can create an instance of a Zend_Db_Select object using the select() method of a Zend_Db_Adapter_Abstract object. This can be used to build &#8216;SELECT&#8217; queries. When building the query, you can add clauses of the query one by one. There is a separate method to add each clause to the Zend_Db_Select object. For example:</p>
<blockquote><p>To Build this query:<br />
&#8220;SELECT product_id, product_name, price FROM &#8220;products&#8221; WHERE price &gt; 100.00&#8243; //this is not a magento query</p></blockquote>
<blockquote><p>We can write:<br />
$select = $read-&gt;select()-&gt;from(&#8216;products&#8217;, array(&#8216;product_id&#8217;, &#8216;product_name&#8217;, &#8216;price&#8217;))-&gt;where(&#8216;price &gt; 100.00&#8242;);</p></blockquote>
<p>More on how to build &#8216;SELECT&#8217; statements using Zend here : <a href="http://framework.zend.com/manual/en/zend.db.select.html">http://framework.zend.com/manual/en/zend.db.select.html</a>.</p>
<p><strong>Lets look at an example:</strong></p>
<p>What if you want to load all products in a particular category:</p>
<blockquote><p>$resource = Mage::getSingleton(&#8216;core/resource&#8217;);<br />
$read = $resource-&gt;getConnection(&#8216;core_read&#8217;);<br />
$categoryProductTable=$read-&gt;getTableName(&#8216;category/category_product&#8217;)<br />
$select = $read-&gt;select()-&gt;from(array(&#8216;cp&#8217;=&gt;$categoryProductTable))-&gt;where(&#8216;cp.category_id=?&#8217;, 3);<br />
$products=$read-&gt;fetchAll($select);<br />
foreach($products as $row)<br />
{<br />
$product = Mage::getModel(&#8216;catalog/product&#8217;)-&gt;load($row['product_id']);<br />
echo $product-&gt;getName();<br />
}</p></blockquote>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/magentotuts.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/magentotuts.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/magentotuts.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/magentotuts.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/magentotuts.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/magentotuts.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/magentotuts.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/magentotuts.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/magentotuts.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/magentotuts.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/magentotuts.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/magentotuts.wordpress.com/142/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/magentotuts.wordpress.com/142/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/magentotuts.wordpress.com/142/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magentotuts.wordpress.com&amp;blog=7875464&amp;post=142&amp;subd=magentotuts&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://magentotuts.wordpress.com/2009/06/01/database-concepts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fc73ced983409690f072ce6902f4de64?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">magentotuts</media:title>
		</media:content>
	</item>
		<item>
		<title>Some Important Mage functions : getModel(),getData(),getSingleton()</title>
		<link>http://magentotuts.wordpress.com/2009/05/27/some-important-mage-functions/</link>
		<comments>http://magentotuts.wordpress.com/2009/05/27/some-important-mage-functions/#comments</comments>
		<pubDate>Wed, 27 May 2009 07:11:37 +0000</pubDate>
		<dc:creator>magentotuts</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://magentotuts.wordpress.com/?p=133</guid>
		<description><![CDATA[We will be looking into some important methods used frequently in Magento like getModel(), getData(), getSingleton().. getModel() (To create an instance of a Model class) : The getModel() function is used to create an instance of a Model class. For example $Product = Mage::getModel(’catalog/product’); would basically tell Magento to create an instance of Mage_Catalog_Model_Product class. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magentotuts.wordpress.com&amp;blog=7875464&amp;post=133&amp;subd=magentotuts&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>We will be looking into some important methods used frequently in Magento like getModel(), getData(), getSingleton()..</p>
<p><strong>getModel() (To create an instance of a Model class) :</strong></p>
<p>The getModel() function is used to create an instance of a Model class. For example</p>
<blockquote><p>$Product = Mage::getModel(’catalog/product’);</p></blockquote>
<p>would basically tell Magento to create an instance of Mage_Catalog_Model_Product class. (ie. Mage/Catalog/Model/Product.php). If we now echo the get_class($Product) we would get the Mage_Catalog_Model_Product text displayed in our browser. You can use all methods defined in Product.php. Some useful methods include getName, getPrice, getTypeId, getStatus which we can execute like:</p>
<blockquote><p>echo ‘Product name: ‘ . $Product-&gt;getName();<br />
echo ‘Product price: ‘ . $Product-&gt;getPrice();</p></blockquote>
<p>However, the above code wont give you anything. You will not see any price displayed in the browser. This is because you haven’t loaded the product using load() method. We have to use the load method to load some data into our newly instantiated object.</p>
<blockquote><p>$Product-&gt;load(53); where 53 is the product id.</p></blockquote>
<p><strong>getData() (To get relevant data from the object instance)</strong></p>
<p>This function is used to get relevant data from the object instance. Let’s say you want to retrieve the SKU value. You can use some other method for that like getSku() method that needs to be executed on object of Product type or you can:</p>
<blockquote><p>echo $Product-&gt;getData(’sku’);</p></blockquote>
<p>getData can be executed with or without any parameters passed to it. If you execute it without any parameters you get the array variable as a result. You can’t directly echo the array. You would have to map it to some field, like echo $arayVar['someField']. What are all the available fields? To find out you can do something like</p>
<blockquote><p>echo ‘&lt;pre&gt;’;<br />
print_r($Product-&gt;getData());<br />
echo ‘&lt;/pre&gt;’;</p></blockquote>
<p>You can get the sku of the product by:</p>
<blockquote><p>$ProductData = $Product-&gt;getData();<br />
echo $ProductData-&gt;sku;</p></blockquote>
<p>or:</p>
<blockquote><p>echo $Product-&gt;getData(&#8216;sku&#8217;)</p></blockquote>
<p>Another example:</p>
<blockquote><p>$ProductData = $Product-&gt;getData();<br />
$StockItem = $ProductData-&gt;stock_item;</p></blockquote>
<p>Now your $StockItem variable is a object of type Mage_CatalogInventory_Model_Stock_Item and you can go ahead and use the same principle used until this point to find it’s methods and the data it holds.</p>
<p>First use the getModel to create the instance of object then you use getData to retrieve the data from that instance.</p>
<p><strong>getSingleton():</strong></p>
<p>One of the important architectural feature is it’s Singleton design pattern. In short, Singleton design pattern ensures a class has only one instance. Therefore one should provide a global point of access to that single instance of a class.</p>
<p>So when you are using getSingleton you are calling already instantiated object. So if you get the empty array as a result, it means the object is empty. Only the blueprint is there, but nothing is loaded in it.</p>
<p><strong>Registry:<br />
</strong></p>
<p>We had told that Magento provides global point of access to single instance of classes. How does Magento do it ?. This is done by using an array called registry in Mage.php.</p>
<p>Checkout the Mage.php file and you will see an array variable called _registry.</p>
<p>In order to provide global point of access for an instance of a class we must register the object into the registry array by using a function called register. For example:</p>
<p>Mage::register(&#8216;events&#8217;, new Varien_Event_Collection());<br />
Mage::register(&#8216;config&#8217;, new Mage_Core_Model_Config());</p>
<p>Here is the code of the register() function:</p>
<blockquote><p>public static function register($key, $value, $graceful = false)<br />
{<br />
if(isset(self::$_registry[$key])) {<br />
if ($graceful) {<br />
return;<br />
}<br />
Mage::throwException(&#8216;Mage registry key &#8220;&#8216;.$key.&#8217;&#8221; already exists&#8217;);<br />
}<br />
self::$_registry[$key] = $value;}</p></blockquote>
<p>Basically what it does it registers an object with name as $key and the instance as $value into the registry array. You can also unregister an object using the unregister() function.</p>
<p>Whenever we want to call an object from the registry we use the registry() function. For example in the getConfig() method:</p>
<blockquote><p>public static function getConfig()<br />
{<br />
return Mage::registry(&#8216;config&#8217;);<br />
}</p></blockquote>
<p>Previously we had registered an  instance of Mage_Core_Model_Config as ‘config’. The getConfig() function returns that instance. Here is the code for registry() function:</p>
<blockquote><p>public static function registry($key)<br />
{<br />
if (isset(self::$_registry[$key])) {<br />
return self::$_registry[$key];<br />
}<br />
return null;<br />
}</p></blockquote>
<p><strong>Analyzing the getModel() and getSingleton() code:</strong></p>
<p>The getModel() and getSingleton() functions works by using this registry. Here is the code for the getModel() function:</p>
<blockquote><p>public static function getModel($modelClass=”, $arguments=array())<br />
{<br />
return Mage::getConfig()-&gt;getModelInstance($modelClass, $arguments);<br />
}</p></blockquote>
<p>Basically it gets the Config object (This object is formed by parsing all the config.xml files, so it contains all config details of all moules) and then makes an instance of the model that is specified by the $modelClass argument.(for example if $modelClass is &#8216;catalog/product it creates an instance of Mage_Catalog_Model_Product)</p>
<p>Now take a look at the getSingleton Method:</p>
<blockquote><p>public static function getSingleton($modelClass=&#8221;, array $arguments=array())<br />
{<br />
$registryKey = &#8216;_singleton/&#8217;.$modelClass;<br />
if (!Mage::registry($registryKey)) {<br />
Mage::register($registryKey, Mage::getModel($modelClass, $arguments));<br />
}<br />
return Mage::registry($registryKey);<br />
}</p></blockquote>
<p>Basically it checks wheter an instance of that class is already existing, if so return that instance else create a new instance and register it as ‘_singleton/$modelClass’.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/magentotuts.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/magentotuts.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/magentotuts.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/magentotuts.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/magentotuts.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/magentotuts.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/magentotuts.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/magentotuts.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/magentotuts.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/magentotuts.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/magentotuts.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/magentotuts.wordpress.com/133/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/magentotuts.wordpress.com/133/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/magentotuts.wordpress.com/133/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magentotuts.wordpress.com&amp;blog=7875464&amp;post=133&amp;subd=magentotuts&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://magentotuts.wordpress.com/2009/05/27/some-important-mage-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fc73ced983409690f072ce6902f4de64?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">magentotuts</media:title>
		</media:content>
	</item>
		<item>
		<title>Understanding Controllers</title>
		<link>http://magentotuts.wordpress.com/2009/05/26/understanding-controllers/</link>
		<comments>http://magentotuts.wordpress.com/2009/05/26/understanding-controllers/#comments</comments>
		<pubDate>Tue, 26 May 2009 06:47:14 +0000</pubDate>
		<dc:creator>magentotuts</dc:creator>
				<category><![CDATA[Magento]]></category>

		<guid isPermaLink="false">http://magentotuts.wordpress.com/?p=121</guid>
		<description><![CDATA[For understanding controllers we need to know how the Magento processes requests from the browser. Look at the following diagram which shows the page request flow. This diagram will give you an idea of the job of controllers. Job of the controller: The controller receives a URL request from the browser. The controller has to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magentotuts.wordpress.com&amp;blog=7875464&amp;post=121&amp;subd=magentotuts&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>For understanding controllers we need to know how the Magento processes requests from the browser. Look at the following diagram which shows the page request flow. This diagram will give you an idea of the job of controllers.</p>
<p><a href="http://www.magentocommerce.com/wiki/_detail/general/doc/page-request-flow.png"><img class="aligncenter size-full wp-image-122" title="page-request-flow" src="http://magentotuts.files.wordpress.com/2009/05/page-request-flow.jpg?w=480&#038;h=338" alt="page-request-flow" width="480" height="338" /></a></p>
<p><strong>Job of the controller:</strong></p>
<p>The controller receives a URL request from the browser. The controller has to process this request to find what code to run. This is done via a router. Routing is the process of taking a URL and decomposing it into parameters to determine which module, controller, and action of that controller should receive the request. The URL gets “routed” to a particular Controller, which in turns tells Magento what to do. The Controller tells Magento which layout is to be used. This determines which modules are put into place, which in turn tells Magento what Views to output. The data from the Models are given to the Views to be displayed. In the scheme of things here, Blocks fit roughly between the View and the Model.</p>
<p><strong>Decomposing the URL:</strong></p>
<p>Now we will see how a browser request to a URL gets translated into module execution. Generally speaking any URL can be deconstructed as follows:</p>
<p><img class="aligncenter size-full wp-image-125" title="decomposeurl" src="http://magentotuts.files.wordpress.com/2009/05/decomposeurl.jpg?w=480&#038;h=228" alt="decomposeurl" width="480" height="228" /></p>
<p>As you can see the above URL has been decomposed to get the module as ‘customer’, the controller as ‘AccountController’ and the action to be performed as ‘indexAction()’. Checkout the AccountController file in Mage\Customer\controllers\ . You will see an indexAction() function. This is the function that is executed by the above URL request.</p>
<p><img class="aligncenter size-full wp-image-126" title="indexAction" src="http://magentotuts.files.wordpress.com/2009/05/indexaction.jpg?w=480&#038;h=244" alt="indexAction" width="480" height="244" /></p>
<p>If the URL was http://example.com/magento/(index.php)/customer/account/login then the loginAction() will be executed.</p>
<p>So The front controller (the controller that receives requests from browser) “dispatches” the request to its internal list of “<em>routers</em>” and determines if any of the routers “<em>match()</em>” the request’s parameters. If so, then a new MVC Controller (‘AccountController’ in this case) is created from the matching module and, again, the request is “dispatched” to this controller object. The final MVC-style controller is technically a “<em>Front Action</em>” (Notice that AccountController extends Mage_Core_Controller_Front_Action).This new Action object dynamically calls one of its own <em>action </em>methods (‘indexAction()’) and marks the request as being “dispatched” (i.e. finished).</p>
<p><strong>How the routers find a match?</strong></p>
<p>The front controller has an array of “<em>routers</em>” that it uses to decide which module the URL should trigger. This correlation between URL and module name is defined in the config.xml files of the modules. Checkout the config.xml file of the Customer module you will see this:</p>
<p><img class="aligncenter size-full wp-image-127" title="customerrouterxml" src="http://magentotuts.files.wordpress.com/2009/05/customerrouterxml.jpg?w=403&#038;h=179" alt="customerrouterxml" width="403" height="179" /></p>
<p>Once a router has found a match of the first part of the URL to a defined frontName<strong> </strong> value from the XML, this value gets directly translated into a module name with a little adjustment to the capitalization of the words (ie. ‘customer’ to ‘Customer’) The controller and the action names are taken from the URL.</p>
<p>What if you only enter example.com/customer/ and not specify the controller and action you want. Find out what result you get. You will be directed to the 404 Not Found error page. How did that happen? If any value is missing, the defaults are taken from the config.xml of the Core module. If any indicators of module, controller, or action are missing from the URL the values are read from the default tag under web. By default, the CMS supplies these XML values it its own config.xml file. You can change these values by going to System-&gt;Configuration-&gt;Web.</p>
<p><img class="aligncenter size-full wp-image-128" title="defaultroute" src="http://magentotuts.files.wordpress.com/2009/05/defaultroute.jpg?w=479&#038;h=183" alt="defaultroute" width="479" height="183" /></p>
<p><strong>Actions:</strong></p>
<p><strong></strong>Actions are classes that extend Mage_Core_Controller_Front_Action which, in turn, extends Mage_Core_Controller_Varien_Action.(‘AccountController’ is an Action). A request is dispatched to an action method (‘indexAction()’). Action methods have the word “Action” appended to their names to distinguish them from normal class methods. Appending a word to the method name also helps to stop people from running unexpected methods from the URL. Imagine someone requesting example.com/index.php/customer/account/__destruct. If the system did not protect action names, the resulting method call would look something like this:</p>
<p>$controllerInstance-&gt;__destruct();</p>
<p>Something like this could potentially be a vector to open up attacks on your site. So Magento protects the action method names by appending Action to any value taken from the URL. Action and action methods are where the primary business logic for a request happens. Typically the action methods will load a model or two based on IDs or other URL parameters, kick off a few methods of these models, and then run the layout sequence.</p>
<p>Launch your browser and type <a href="http://127.0.0.1/magento/index.php/customer/account/login/">http://127.0.0.1/magento/index.php/customer/account/login/</a>. This should execute the loginAction() method in AccountController class of Customer module.</p>
<p>The Output will be as follows:</p>
<p><img class="aligncenter size-full wp-image-129" title="login" src="http://magentotuts.files.wordpress.com/2009/05/login.jpg?w=480&#038;h=208" alt="login" width="480" height="208" /></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/magentotuts.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/magentotuts.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/magentotuts.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/magentotuts.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/magentotuts.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/magentotuts.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/magentotuts.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/magentotuts.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/magentotuts.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/magentotuts.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/magentotuts.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/magentotuts.wordpress.com/121/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/magentotuts.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/magentotuts.wordpress.com/121/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magentotuts.wordpress.com&amp;blog=7875464&amp;post=121&amp;subd=magentotuts&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://magentotuts.wordpress.com/2009/05/26/understanding-controllers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fc73ced983409690f072ce6902f4de64?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">magentotuts</media:title>
		</media:content>

		<media:content url="http://magentotuts.files.wordpress.com/2009/05/page-request-flow.jpg" medium="image">
			<media:title type="html">page-request-flow</media:title>
		</media:content>

		<media:content url="http://magentotuts.files.wordpress.com/2009/05/decomposeurl.jpg" medium="image">
			<media:title type="html">decomposeurl</media:title>
		</media:content>

		<media:content url="http://magentotuts.files.wordpress.com/2009/05/indexaction.jpg" medium="image">
			<media:title type="html">indexAction</media:title>
		</media:content>

		<media:content url="http://magentotuts.files.wordpress.com/2009/05/customerrouterxml.jpg" medium="image">
			<media:title type="html">customerrouterxml</media:title>
		</media:content>

		<media:content url="http://magentotuts.files.wordpress.com/2009/05/defaultroute.jpg" medium="image">
			<media:title type="html">defaultroute</media:title>
		</media:content>

		<media:content url="http://magentotuts.files.wordpress.com/2009/05/login.jpg" medium="image">
			<media:title type="html">login</media:title>
		</media:content>
	</item>
		<item>
		<title>Writing a Custom Module</title>
		<link>http://magentotuts.wordpress.com/2009/05/25/writing-a-custom-module/</link>
		<comments>http://magentotuts.wordpress.com/2009/05/25/writing-a-custom-module/#comments</comments>
		<pubDate>Mon, 25 May 2009 14:15:04 +0000</pubDate>
		<dc:creator>magentotuts</dc:creator>
				<category><![CDATA[Magento]]></category>

		<guid isPermaLink="false">http://magentotuts.wordpress.com/?p=106</guid>
		<description><![CDATA[Creating a custom module is quite easy but it does involve several steps. This post describes the steps that need to be followed to create a new module. STEP ONE: (Creating the Directory Structure) You will be creating your module in the app/code/local directory. First create a directory and call it ‘MyPackage’. This will be [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magentotuts.wordpress.com&amp;blog=7875464&amp;post=106&amp;subd=magentotuts&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Creating a custom module is quite easy but it does involve several steps. This post describes the steps that need to be followed to create a new module.</p>
<p><strong>STEP ONE: (Creating the Directory Structure)<br />
</strong></p>
<p>You will be creating your module in the app/code/local directory. First create a directory and call it ‘MyPackage’. This will be your new package where you can create modules. (Similar to Mage Package). Next create a directory and name it ‘MyModule’. This is your Module directory which will contain the required files like models, blocks, controller,etc..</p>
<p><strong>STEP TWO: (Registering the Module)<br />
</strong></p>
<p>You need to inform Magento that you have a custom module.. This is done by creating an XML file in /app/etc/modules, MyPackage_All.xml.<strong> </strong>Notice the _All in the xml file name. you can declare all of my modules here.</p>
<blockquote>
<p style="text-align:left;">&lt;?xml version=&#8221;1.0&#8243;?&gt;<br />
&lt;config&gt;<br />
&lt;modules&gt;<br />
&lt;MyPackage_MyModule&gt;<br />
&lt;active&gt;true&lt;/active&gt;<br />
&lt;codePool&gt;local&lt;/codePool&gt;<br />
&lt;/MyPackage_MyModule&gt;<br />
&lt;/modules&gt;<br />
&lt;/config&gt;</p></blockquote>
<p>This code is used to inform Magento that there is an active module (you can turn it off from here by setting ‘active’ to false). Also that it is located in the ‘local’ code pool.</p>
<p>After performing this step you can check the result by going to System-&gt;Configuration-&gt;Advanced. You will see a list of available modules and in that list MyPackage_MyModule will be present.</p>
<p style="text-align:center;"><img class="size-full wp-image-113 aligncenter" title="newmodule" src="http://magentotuts.files.wordpress.com/2009/05/newmodule.jpg?w=480&#038;h=91" alt="newmodule" width="480" height="91" /></p>
<p><strong>STEP THREE: (Creating a Block Class)<br />
</strong></p>
<p>Next we need to create the module. Go to the app/code/local/MyPackage/MyModule Directory and create a directory called ‘Block’. Create a php file called View.php and copy the following code:</p>
<blockquote><p>&lt;?php<br />
class MyPackage_MyModule_Block_View extends Mage_Core_Block_Template {<br />
public function myFunction(){<br />
return “Hello World!“;<br />
}<br />
}<br />
?&gt;</p></blockquote>
<p>We have created a simple block which contains a function that returns the string ‘Hello World’.</p>
<p><strong>STEP FOUR: (Enter Config info for module)<br />
</strong></p>
<p>Now we need to make a config.xml file in app/code/local/MyPackage/MyModule/etc directory. This is done to enter configuration information for the module. Copy the following contents:</p>
<blockquote><p>&lt;?xml version=&#8221;1.0&#8243; ?&gt;<br />
&lt;config&gt;<br />
&lt;modules&gt;<br />
&lt;MyPackage_MyModule&gt;<br />
&lt;version&gt;0.1.0&lt;/version&gt;<br />
&lt;/MyPackage_MyModule&gt;<br />
&lt;/modules&gt;<br />
&lt;global&gt;<br />
&lt;blocks&gt;<br />
&lt;helloworld&gt;<br />
&lt;class&gt;MyPackage_MyModule_Block&lt;/class&gt;<br />
&lt;/helloworld&gt;<br />
&lt;/blocks&gt;<br />
&lt;/global&gt;<br />
&lt;/config&gt;</p></blockquote>
<p>This informs Magento of the module version. Version matters when you set up your module to be update-able. (A newer version will inform Magento to run the update files if you have them).</p>
<p>It also informs Magento that the module contains block files which are found in MyPackage/MyModule/Block/  directory. The class name should be “MyPackage_MyModule_Block”.</p>
<p><strong>STEP FIVE: (Creating a Template file)<br />
</strong></p>
<p>Now we need to create a template file which uses the View Block Class to display the message “Hello World”. Create a template (phtml) called view.phtml in the following directory<strong>: </strong><em>app\design\frontend\default\default\template\mymodule\view.phtml.</em></p>
<blockquote><p>&lt;div&gt;&lt;span&gt;&lt;strong&gt;This is the output of the MyModule module:&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;  &lt;span style=&#8221;color:#FF9933;&#8221;&gt;<br />
&lt;?php<br />
echo $this-&gt;myFunction();<br />
?&gt;<br />
&lt;/span&gt;<br />
&lt;/div&gt;</p></blockquote>
<p>This just outputs some HTML and also runs the myFunction() function from our block (View.php).</p>
<p><strong>STEP SIX: (Using the Module)<br />
</strong></p>
<p>The module is now ready for use. You can view the output by two ways.</p>
<p>One way is to add the following code in a cms page:</p>
<blockquote><p>{{block type=&#8221;mypackage_mymodule/view&#8221;  template=&#8221;mymodule/view.phtml&#8221; }}</p></blockquote>
<p>Another way is to enter it as a layout update:</p>
<blockquote><p>&lt;reference name=&#8221;right&#8221;&gt;<br />
&lt;block type=&#8221;mymodule/view&#8221; name=&#8221;mymodule&#8221; template=&#8221;mymodule/view.phtml&#8221;/&gt;<br />
&lt;/reference&gt;</p></blockquote>
<p><strong>RESULT:</strong></p>
<p>This will be the final output of your module:</p>
<p><img class="aligncenter size-full wp-image-117" title="helloworld" src="http://magentotuts.files.wordpress.com/2009/05/helloworld.jpg?w=266&#038;h=316" alt="helloworld" width="266" height="316" /></p>
<p><strong><br />
</strong></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/magentotuts.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/magentotuts.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/magentotuts.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/magentotuts.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/magentotuts.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/magentotuts.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/magentotuts.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/magentotuts.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/magentotuts.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/magentotuts.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/magentotuts.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/magentotuts.wordpress.com/106/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/magentotuts.wordpress.com/106/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/magentotuts.wordpress.com/106/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magentotuts.wordpress.com&amp;blog=7875464&amp;post=106&amp;subd=magentotuts&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://magentotuts.wordpress.com/2009/05/25/writing-a-custom-module/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/fc73ced983409690f072ce6902f4de64?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">magentotuts</media:title>
		</media:content>

		<media:content url="http://magentotuts.files.wordpress.com/2009/05/newmodule.jpg" medium="image">
			<media:title type="html">newmodule</media:title>
		</media:content>

		<media:content url="http://magentotuts.files.wordpress.com/2009/05/helloworld.jpg" medium="image">
			<media:title type="html">helloworld</media:title>
		</media:content>
	</item>
	</channel>
</rss>
