<?xml version="1.0"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>I'm Learning SilverStripe</title>
		<link>http://www.sslearn.info/sslearn/home/</link>
		<atom:link href="http://www.sslearn.info/sslearn/home/" rel="self" type="application/rss+xml" />
		<description></description>

		
		<item>
			<title>Displays month and year options on the calendar datefield</title>
			<link>http://www.sslearn.info/sslearn/displays-month-and-year-options-on-the-calendar-datefield/</link>
			<description>&lt;p&gt;Silverstripe has a datefield. This field is used to fill the dates on the form. In version 2.4 by default, this field is only a text field to fill in the date format as &quot;mm / dd / yyyy&quot;. But this field can be custom to display the calendar of the jquery javascript-UI. How to use it fairly easily:&lt;/p&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $datefield = new DateField(&quot;Date&amp;rdquo;, &quot;Date&quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $datefield-&amp;gt;setConfig('showcalendar', true);&lt;/pre&gt;
&lt;p&gt;Calendar of this field can actually be used to fill out the form. But has lacked at the time of filling I have a problem to change the month and year of filling, for example when filling date of birth. Back and forward buttons at the top of this field can only change one month backward or forward.&lt;br /&gt;&lt;br /&gt;To activate the option in the calendar month and year this field, the way he is editing files sapphire / forms / DateField.php at line number 528 by adding two additional array variables:&lt;/p&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; 'changeYear' =&amp;gt; true,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; 'changeMonth' =&amp;gt; true,&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;So variable conf becomes:&lt;/p&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $conf = array(&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; 'showcalendar' =&amp;gt; true,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; 'dateFormat' =&amp;gt; $format,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; 'changeYear' =&amp;gt; true,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; 'changeMonth' =&amp;gt; true,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; );&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;Array variable changeYear and changeMonth a jquery datepicker-UI option to display a selection of months and years. Later after that on datefield calendar will be as below:&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;left&quot; src=&quot;http://www.sslearn.info/sslearn/assets/Displays-options-months-and-years-on-the-calendar-datefield/dtpicker2.png&quot; width=&quot;308&quot; height=&quot;243&quot; alt=&quot;&quot; title=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description>
			<pubDate>Thu, 26 Aug 2010 18:40:27 -0500</pubDate>
			
			<guid>http://www.sslearn.info/sslearn/displays-month-and-year-options-on-the-calendar-datefield/</guid>
		</item>
		
		<item>
			<title>Creating Simple Page Counter</title>
			<link>http://www.sslearn.info/sslearn/creating-simple-page-counter/</link>
			<description>&lt;p&gt;Page counter sometimes we need to know the number of the many people who read a page on our website. From page counters, we can also get information about the pages most often read by people. On silverstripe there is no page counters function, so we have to create your own.&lt;/p&gt;
&lt;p&gt;To create a page counter is very easy. We just need to create a DataObject that contains two fields namely Counter and Page. Counter Field&amp;nbsp; used to store counter&amp;nbsp; data. Later this DataObject we relate to Page with Page field. Here we create an dataobject separate from page object to avoid versioning page data on each data update.&lt;/p&gt;
&lt;p&gt;This Data Object can we save it into a file, for example, let's call the file with a name PageCounter.php in mysite directory.&lt;/p&gt;
&lt;p&gt;PageCounter.php&lt;/p&gt;
&lt;pre&gt;&amp;lt;? &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; class PageCounter extends DataObject{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; static $db = array(&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; 'Counter' =&amp;gt; 'Int',&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; );&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; static $has_one = array(&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; 'Page' =&amp;gt; 'Page',&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; );&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;Next we just add the following line in the init() function&amp;nbsp; of Page_Controller class in Page.php file.&lt;/p&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $pagecounter = DataObject::get_one(&quot;PageCounter&quot;,&quot;PageID='$this-&amp;gt;ID'&quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(!$pagecounter){&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; $pagecounter = new PageCounter();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; $pagecounter-&amp;gt;PageID=$this-&amp;gt;ID;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $pagecounter-&amp;gt;Counter = $pagecounter-&amp;gt;Counter+1;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $pagecounter-&amp;gt;write();&lt;/pre&gt;
&lt;p&gt;Next we must create a function to get value from the page counter object. This function is created inside the Page_Controller class on Page.php file. The goal is only to take counters data.&lt;/p&gt;
&lt;pre&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public function pagecount(){&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; $pagecounter = DataObject::get_one(&quot;PageCounter&quot;,&quot;PageID='$this-&amp;gt;ID'&quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; return $pagecounter-&amp;gt;Counter;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/pre&gt;
&lt;p&gt;This function we can use in our template page.&lt;/p&gt;</description>
			<pubDate>Sun, 09 May 2010 09:15:17 -0500</pubDate>
			
			<guid>http://www.sslearn.info/sslearn/creating-simple-page-counter/</guid>
		</item>
		
		<item>
			<title>Creating Paging (per page) for Query Results</title>
			<link>http://www.sslearn.info/sslearn/creating-paging-per-page-for-query-results/</link>
			<description>&lt;p&gt;There's one of my friends asking how to create paging in &lt;a href=&quot;http://www.sslearn.info/sslearn/how-to-querying-pages-in-silverstripe/&quot;&gt;query results on silverstripe&lt;/a&gt;?&lt;/p&gt;
&lt;p&gt;It is to display the query results we must make the results is limited per page. Paging is the term used to regulate the number of query results are displayed per page. If not using the paging all the query results will be displayed on one page and it is not reasonable if it is implemented on the website. We can imagine, if the google.com search results do not display in the form of paging, then we must make scrolling to find the search results to the bottom of result page.&lt;/p&gt;
&lt;p&gt;In fact Silverstripe paging facilities already provided by the DataObjectSet object. This object is used to store a collection of DataObject. DataObjek is a Class to represent the Silverstripe Database. You can read how to use DataObject in &lt;a href=&quot;http://doc.silverstripe.org/doku.php?id=dataobject&quot; target=&quot;_blank&quot;&gt;http://doc.silverstripe.org/doku.php?id=dataobject&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Create paging on silverstripe actually easy. We class to use Class DataObjectSet on our query function. Suppose we make a function ArticlePageList whose content type to display the list of pages that we will restrict ArticlePage 10 per page, its code as follows:&lt;/p&gt;
&lt;pre&gt;public function ArticlePageList($limit=10){&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $start = isset($_GET['start']) ? (int) $_GET['start'] : 0;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $list = DataObject::get(&quot;ArticlePage&quot;, &quot;&quot;, &quot;&quot;,&quot;&quot;,&quot;$start , $limit&quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return $list;&lt;br /&gt;}&lt;/pre&gt;
&lt;p&gt;In functions there is a $list variable which is the DataObjectSet output of the static method DataObject: get. In this function we also determine the limit of the number of query results. Then on the template we can create the following code to display it:&lt;/p&gt;
&lt;pre&gt;&amp;lt;ul&amp;gt;&lt;br /&gt;&amp;lt;% control ArticlePageList %&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;li&amp;gt;&amp;lt;a href=&quot;$Link&quot;&amp;gt;$Title&amp;lt;/a&amp;gt;&amp;lt;p&amp;gt;$Content.Summary(50)&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&amp;nbsp; &lt;br /&gt;&amp;lt;% end_control %&amp;gt;&lt;br /&gt;&amp;lt;/ul&amp;gt;&lt;/pre&gt;
&lt;p&gt;Above code wil be shown a list of type list of pages ArticlePage limit to 10 ArticlePage per Page.&lt;/p&gt;
&lt;p&gt;To make the paging, we just use the method that has been provided by DataObjectSet. Method which we can use for paging is as follows:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;MoreThanOnePage()&lt;/strong&gt;, this method is used to determine if the output of the query results more than one page or not.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;NextLink()&lt;/strong&gt;, this method is used to get the URL for the next page.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;NotFirstPage()&lt;/strong&gt;, this method is used to provide information that the query results are displayed not on the first page.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;NotLastPage()&lt;/strong&gt;, this method is used to provide information that the query results are displayed not on the last page.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;PrevLink()&lt;/strong&gt;, this method is used to obtain the URL to the previous page.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;to use the methods, we can directly implements it on the template silverstripe as below:&lt;/p&gt;
&lt;pre&gt;&amp;lt;% if LatestChild.NotFirstPage %&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;a class=&quot;prev&quot; href=&quot;$LatestChild.PrevLink&quot;&amp;gt;&amp;amp;laquo; Sebelumnya&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;% end_if %&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;lt;% if LatestChild.NotLastPage %&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;a class=&quot;next&quot; href=&quot;$LatestChild.NextLink&quot;&amp;gt;Berikutnya &amp;amp;raquo;&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;% end_if %&amp;gt;&lt;/pre&gt;
&lt;p&gt;In the above code there will be displayed a link to the previous page and next page for the ArticlePage list.&lt;/p&gt;</description>
			<pubDate>Tue, 20 Apr 2010 04:23:15 -0500</pubDate>
			
			<guid>http://www.sslearn.info/sslearn/creating-paging-per-page-for-query-results/</guid>
		</item>
		
		<item>
			<title>HOW TO Querying Pages in Silverstripe</title>
			<link>http://www.sslearn.info/sslearn/how-to-querying-pages-in-silverstripe/</link>
			<description>&lt;p&gt;Silverstripe uses a class called DataObject to interact with databases. We could say that every interaction with the database will be performed by the DataObject. For example we can do a query for any data we want on the Silverstripe with this object.&lt;/p&gt;
&lt;p&gt;In &lt;a href=&quot;http://www.sslearn.info/sslearn/creating-a-new-page-type/&quot;&gt;making a new page&lt;/a&gt; type called ArticlePage, you may be wondering, &quot;How do I create a list of ArticlePage pages?&quot;. We know that every page on silverstripe will be stored in MySQL database. So the answer to that question is that we live make a query on the MySQL database to get the entire list page and we'll display it on other pages.&lt;/p&gt;
&lt;p&gt;Actually there are two ways to do it all.&lt;/p&gt;
&lt;h4&gt;&lt;br /&gt;&lt;/h4&gt;
&lt;h4&gt;1. Querying If the page it was on the child of a particular page&lt;/h4&gt;
&lt;p&gt;If the page you want to be queried is in the child of a page, we just call the control named Children in the templates (.ss file). Children will give output an array contain objects of the child page. Each array will have the attributes and methods in accordance with the type of pages.&lt;/p&gt;
&lt;p&gt;Example we write like this:&lt;/p&gt;
&lt;pre&gt;&amp;lt;ul&amp;gt;&lt;br /&gt;&amp;lt;% control &lt;strong&gt;Children&lt;/strong&gt; %&amp;gt;&lt;br /&gt;	&amp;lt;li&amp;gt;&amp;lt;a href=&quot;$Link&quot;&amp;gt;$Title&amp;lt;/a&amp;gt;&amp;lt;p&amp;gt;$Content.Summary(50)&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;	&lt;br /&gt;&amp;lt;% end_control %&amp;gt;&lt;br /&gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;On that page will be shown a html list that contains a list of titles and summaries from the pages of his children.&lt;/p&gt;
&lt;h4&gt;2. Querying If the pages are not on the child of a particular page&lt;/h4&gt;
&lt;p&gt;This second condition, we must create a method on the controller class of page you want to display a list of other pages. For example a page that wants to display the list is Page and type of page you want to make the list is ArticlePage. Next we must create a new method on the controller of Page.&lt;/p&gt;
&lt;p&gt;mysite/code/Page.php&lt;/p&gt;
&lt;pre&gt;&lt;strong&gt;class&lt;/strong&gt; Page_Controller &lt;strong&gt;extends&lt;/strong&gt; ContentController{&lt;br /&gt;. . . .&lt;br /&gt;	&lt;strong&gt;public&lt;/strong&gt; &lt;strong&gt;function&lt;/strong&gt; ArticlePageList($limit=10){&lt;br /&gt;		$start = isset($_GET['start']) ? (int) $_GET['start'] : 0;&lt;br /&gt;		$list = DataObject::get(&quot;ArticlePage&quot;, &quot;&quot;, &quot;&quot;,&quot;&quot;,&quot;$start , $limit&quot;);&lt;br /&gt;		return $list;&lt;br /&gt;	}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;This method made ArticlePageList will issue DataObjectSet output that contains a collection of DataObject. Function &lt;strong&gt;DataObject::get&lt;/strong&gt; is a function that is used to retrieve an array of &lt;span style=&quot;text-decoration: underline;&quot;&gt;all DataObject(s) named ArticlePage&lt;/span&gt; found on the SiteTree no matter where the hierarchy location. In the method there is a parameter $limit used to determine the amount of data will be taken, for the default 10 data will be taken.&lt;/p&gt;
&lt;p&gt;Furthermore, to use these methods we should call ArticlePageList controls on the template.&lt;/p&gt;
&lt;pre&gt;&amp;lt;ul&amp;gt;&lt;br /&gt;&amp;lt;% control &lt;strong&gt;ArticlePageList&lt;/strong&gt; %&amp;gt;&lt;br /&gt;	&amp;lt;li&amp;gt;&amp;lt;a href=&quot;$Link&quot;&amp;gt;$Title&amp;lt;/a&amp;gt;&amp;lt;p&amp;gt;$Content.Summary(50)&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;	&lt;br /&gt;&amp;lt;% end_control %&amp;gt;&lt;br /&gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;At the function DataObject::get, there are several parameters that can be used to customize the output of the query. Suppose we want to take ArticlePage whose title has the word &quot;silverstripe&quot;, then the code becomes:&lt;/p&gt;
&lt;pre&gt;$list = DataObject::get(&quot;ArticlePage&quot;, &quot;Title LIKE '%silverstripe%' &quot;, &quot;&quot;,&quot;&quot;,&quot;$start , $limit&quot;);&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;or if we want to display the results sorted by the most recent data, then the code becomes:&lt;/p&gt;
&lt;pre&gt;$list = DataObject::get(&quot;ArticlePage&quot;, &quot;&quot;, &quot;Created DESC&quot;,&quot;&quot;,&quot;$start , $limit&quot;);&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;For more details about the method on the DataObject class you can learn its functions in the &lt;a href=&quot;http://api.silverstripe.org/sapphire/core/DataObject.html#get&quot; target=&quot;_blank&quot;&gt;API Documentation of Class DataObject&lt;/a&gt;.&lt;/p&gt;</description>
			<pubDate>Fri, 02 Apr 2010 01:40:42 -0500</pubDate>
			
			<guid>http://www.sslearn.info/sslearn/how-to-querying-pages-in-silverstripe/</guid>
		</item>
		
		<item>
			<title>Image with Fixed SIze</title>
			<link>http://www.sslearn.info/sslearn/image-with-fixed-size/</link>
			<description>&lt;p&gt;If we read the &lt;a href=&quot;http://doc.silverstripe.org/doku.php?id=image&quot; target=&quot;_blank&quot;&gt;documentation silverstripe about the image&lt;/a&gt;, we will get the reference method used to resize the image on silverstripe. But there are questions on the documentation. How do I change the image size by specifying the width and height of the image from the template file?&lt;/p&gt;
&lt;p&gt;The trick is with SetSize method or PaddedImage. Both these methods set the image proportionately width and height. If the specified width and height are not proportionate, then the image will be given a white background.&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;center&quot; src=&quot;http://www.sslearn.info/sslearn/assets/Fix-size-of-the-Image/SetSize200180-thefallen-wallpaper.jpg&quot; width=&quot;200&quot; height=&quot;180&quot; alt=&quot;&quot; title=&quot;&quot; /&gt;&lt;/p&gt;
&lt;p&gt;What if we want the image that really fit either the width or height in size without a white background?&lt;/p&gt;
&lt;p&gt;I still have not found a function that could be like that on silverstripe. But I have modify files from Image.php to make that function. The trick is to add the following two methods in the Image Class.&lt;/p&gt;
&lt;p&gt;Open the &lt;strong&gt;sapphire/core/model/Image.php&lt;/strong&gt; file&amp;nbsp; then add these two methods in the Image Class:&lt;/p&gt;
&lt;pre&gt;&lt;strong&gt;class&lt;/strong&gt; Image &lt;strong&gt;extends&lt;/strong&gt; File{&lt;br /&gt;....&lt;br /&gt;	&lt;strong&gt;public function&lt;/strong&gt; SetFixedSize($width, $height) {&lt;br /&gt;		return $this-&amp;gt;getFormattedImage('SetReSize', $width, $height);&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;	&lt;strong&gt;public function&lt;/strong&gt; generateSetFixedSize(GD $gd, $width, $height) {&lt;br /&gt;		return $gd-&amp;gt;resize($width, $height);&lt;br /&gt;	}&lt;br /&gt;....&lt;br /&gt;} &lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;After adding these two methods later in the template file (. Ss) we just call the method SetFixedSize to use it like we call the SetSize method. If the Image object named Picture, the template code will be like this:&lt;/p&gt;
&lt;pre&gt;&amp;lt;% control Picture %&amp;gt;&lt;br /&gt;	&amp;lt;% control SetFixedSize(100,120) %&amp;gt;&lt;br /&gt;		&amp;lt;img src=&quot;$URL&quot;/&amp;gt;&lt;br /&gt;	&amp;lt;% end_control %&amp;gt;&lt;br /&gt;&amp;lt;% end_control %&amp;gt;&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;From the snippet above programs will be created fix image size of 100x120 with no white background.&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;center&quot; src=&quot;http://www.sslearn.info/sslearn/assets/Fix-size-of-the-Image/SetReSize200180-thefallen-wallpaper.jpg&quot; width=&quot;200&quot; height=&quot;180&quot; alt=&quot;&quot; title=&quot;&quot; /&gt;&lt;/p&gt;</description>
			<pubDate>Wed, 31 Mar 2010 07:18:38 -0500</pubDate>
			
			<guid>http://www.sslearn.info/sslearn/image-with-fixed-size/</guid>
		</item>
		
		<item>
			<title>Creating Flash Video Object on Silverstripe</title>
			<link>http://www.sslearn.info/sslearn/creating-flash-video-object-on-silverstripe/</link>
			<description>&lt;p&gt;One time ago, I was ever asked to do a web project in which there is a web page containing the video look like on youtube. The video file should be able to upload by their self. Later after the video uploaded, it have to be converted automatically to the .flv format which is will be displayed in the browser.&lt;/p&gt;
&lt;p&gt;Actually, there is extension provided by Silverstripe to manage video called &lt;a href=&quot;http://silverstripe.org/youtube-gallery-module/&quot; target=&quot;_blank&quot;&gt;Youtube Gallery&lt;/a&gt;. But this extension provides only features to take videos from youtube. While my client wants to manage their own videos without using youtube or other video sharing website. For that, I tried to make an object FlashVideo to accommodate a request from my client.&lt;/p&gt;
&lt;h4&gt;Requirements&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;1. FFMPEG&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;FFMPEG is an opensource application that can be used to record, convert and stream audio and video. FFMPEG application is required to be used to convert uploaded video results from the user. These applications can be downloaded for free from &lt;a href=&quot;http://ffmpeg.org/&quot; target=&quot;_blank&quot;&gt;http://ffmpeg.org/&lt;/a&gt;. If you use a hosting server, ask your admin to install this application.&lt;/p&gt;
&lt;p&gt;After downloading and installing on a computer that is used by silverstripe. You must know the path of ffmpeg binary file. If on my computer ffmpeg file is located in /usr/local/bin/ffmpeg. We must make sure ffmpeg run by running the command /usr/local/bin/ffmpeg on the console (microsoft windows in command prompt). Usually output looks like:&lt;/p&gt;
&lt;pre&gt;bash-3.2# /usr/local/bin/ffmpeg&lt;br /&gt;FFmpeg version SVN-r17910, Copyright (c) 2000-2009 Fabrice Bellard, et al.&lt;br /&gt;  configuration: --enable-libmp3lame --enable-shared --disable-mmx&lt;br /&gt;  libavutil     50. 0. 0 / 50. 0. 0&lt;br /&gt;  libavcodec    52.21. 0 / 52.21. 0&lt;br /&gt;  libavformat   52.31. 1 / 52.31. 1&lt;br /&gt;  libavdevice   52. 1. 0 / 52. 1. 0&lt;br /&gt;  libswscale     0. 7. 1 /  0. 7. 1&lt;br /&gt;  built on Mar 10 2009 22:33:58, gcc: 4.0.1 (Apple Inc. build 5465)&lt;br /&gt;At least one output file must be specified&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;If no error message means that ffmpeg is installed correctly.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2. FLV Player&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;We need a flv player to play the video on the web. In general, you can use any flv player. How to get it quite easily, search in google search engine with keywords &quot;flv player&quot; or &quot;flash video player&quot;. I myself use the JW Player which can be downloaded for free at &lt;a href=&quot;http://www.longtailvideo.com/players/jw-flv-player/&quot; target=&quot;_blank&quot;&gt;http://www.longtailvideo.com/players/jw-flv-player/&lt;/a&gt;. Flv player files will be .swf as a flash file.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;FlashVideo Object&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;If you've installed ffmpeg and download flv player then we are ready to begin making the FlashVideo object on Silverstripe.&lt;br /&gt;&lt;br /&gt;First of all, create a directory called FlashVideo in the main directory of silvertripe. Inside the FlashVideo directory, create two directories named code and swf, so the directory structure will look like in the picture below.&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;center&quot; src=&quot;http://www.sslearn.info/sslearn/assets/Creating-FlashVideo-Object-on-Silverstripe/Directory-Structure.png&quot; alt=&quot;Directory Structure&quot; title=&quot;Directory Structure&quot; width=&quot;257&quot; height=&quot;159&quot; /&gt;&lt;/p&gt;
&lt;p&gt;The purpose of creating this directory is to separate the FlashVideo object and its components&amp;nbsp; from the main directory of our website (mysite) directory. However, we could actually make the object in the FlashVideo mysite directory, because its structure is same.&lt;/p&gt;
&lt;p&gt;After making FlashVideo directory, copy the .swf files of flv player that you have downloaded in the swf directory. Flash video player file&amp;nbsp; that I use is called player.swf, this file name will be used in viewing the FlashVideo file.&lt;/p&gt;
&lt;p&gt;Create a file called _config.php in FlashVideo/code/ directory&amp;nbsp; with the following contents:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;FlashVideo/_config.php&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&amp;lt;?&lt;strong&gt;php&lt;/strong&gt; &lt;br /&gt;	&lt;strong&gt;define&lt;/strong&gt;('FFMPEG_BIN',&quot;/usr/local/bin/ffmpeg&quot;);&lt;br /&gt;	$dir = &quot;video&quot;; &lt;br /&gt;&lt;br /&gt;	/*&lt;br /&gt;		Don't change these code bellow if you dont know what you're doing!!&lt;br /&gt;	*/&lt;br /&gt;	&lt;strong&gt;define&lt;/strong&gt;('VIDEO_PATH', ASSETS_PATH.&quot;/&quot;.$dir);&lt;br /&gt;	&lt;strong&gt;define&lt;/strong&gt;(&quot;VIDEO_DIR&quot;, ASSETS_DIR.&quot;/&quot;.$dir);&lt;br /&gt;&lt;br /&gt;	if (!file_exists(VIDEO_PATH)){&lt;br /&gt;		@mkdir(VIDEO_PATH);&lt;br /&gt;		@mkdir(VIDEO_PATH.&quot;/_resampled&quot;);&lt;br /&gt;		@mkdir(VIDEO_PATH.&quot;/_thumbnail&quot;);&lt;br /&gt;	}&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;_config.php configuration File which will FlashVideo use later. Silverstripe MVC will read the _config.php file first before processing the other FlashVideo files in the directory. In this file there is constants named FFMPEG_BIN used to inform the location of the application binary FFMPEG file. Then there is the definition of $dir= &quot;videos&quot;, where $dir is the name of the directory to save the file processing results. This directory ($dir) will be located in the directory assets, so for our flv files can be managed easily through the &lt;strong&gt;Files &amp;amp; Images&lt;/strong&gt; on &lt;a href=&quot;http://www.sslearn.info/sslearn/silverstripe-admin-page-part-2/&quot;&gt;silverstripe admin page&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;After creating the file _config.php, next is create a FlashVideo.php file that is placed on FlashVideo/code/ directory. The contents of FlashVideo.php are as follows:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;FlashVideo/code/FlashVideo.php&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&amp;lt;?php&lt;br /&gt;/* &lt;br /&gt;	Flash Video Model File for uploading Video Files and convert it to flv extension&lt;br /&gt;	By Firnas Nadirman	&lt;br /&gt;*/&lt;br /&gt;&lt;strong&gt;class&lt;/strong&gt; FlashVideo &lt;strong&gt;extends&lt;/strong&gt; File {&lt;br /&gt;&lt;br /&gt;	&lt;strong&gt;public static&lt;/strong&gt; $thumbnail_width = 114;&lt;br /&gt;&lt;br /&gt;	&lt;strong&gt;public static&lt;/strong&gt; $thumbnail_height = 87;&lt;br /&gt;&lt;br /&gt;	&lt;strong&gt;public static&lt;/strong&gt; $cms_thumbnail_width = 100;&lt;br /&gt;&lt;br /&gt;	&lt;strong&gt;public static&lt;/strong&gt; $cms_thumbnail_height = 60;&lt;br /&gt;	&lt;br /&gt;	&lt;strong&gt;public&lt;/strong&gt; $allowedExtensions = array(&quot;mov&quot;,&quot;mp4&quot;,&quot;avi&quot;,&quot;flv&quot;,&quot;mpeg&quot;,&quot;mpg&quot;);	&lt;br /&gt;	&lt;br /&gt;	&lt;strong&gt;public&lt;/strong&gt; $flvplayer = &quot;FlashVideo/swf/player.swf&quot;;&lt;br /&gt;		&lt;br /&gt;	&lt;strong&gt;function&lt;/strong&gt; getOriginalFileURL() {&lt;br /&gt;		return Director::baseURL() . $this-&amp;gt;FileName;&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	&lt;strong&gt;function&lt;/strong&gt; getURL() {&lt;br /&gt;		if (!file_exists($this-&amp;gt;getFlvFilePath())){&lt;br /&gt;			$this-&amp;gt;generateFlv();&lt;br /&gt;		}&lt;br /&gt;		&lt;br /&gt;		return Director::baseURL().$this-&amp;gt;getFlvFileName();&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	&lt;strong&gt;function&lt;/strong&gt; URL() {&lt;br /&gt;		return $this-&amp;gt;getURL();&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	&lt;strong&gt;function&lt;/strong&gt; forTemplate(){&lt;br /&gt;		if(!file_exists($this-&amp;gt;getCMSThumbFilePath())) {&lt;br /&gt;			$this-&amp;gt;getThumbnail($this-&amp;gt;stat(&quot;cms_thumbnail_width&quot;), $this-&amp;gt;stat(&quot;cms_thumbnail_height&quot;), $this-&amp;gt;getCMSThumbFilePath());&lt;br /&gt;		}&lt;br /&gt;		return &quot;&amp;lt;embed width=\&quot;400\&quot; height=\&quot;300\&quot; flashvars=\&quot;file=&quot;.$this-&amp;gt;getURL().&quot;&amp;amp;amp;image=&quot;.$this-&amp;gt;getCMSThumbFileName().&quot;\&quot; allowscriptaccess=\&quot;always\&quot; allowfullscreen=\&quot;true\&quot; quality=\&quot;high\&quot; bgcolor=\&quot;#FFFFFF\&quot; name=\&quot;player\&quot; id=\&quot;player\&quot; style=\&quot;\&quot; src=\&quot;$this-&amp;gt;flvplayer\&quot; type=\&quot;application/x-shockwave-flash\&quot;&amp;gt;&quot;;&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	&lt;strong&gt;function&lt;/strong&gt; getThumbFileName(){&lt;br /&gt;		return VIDEO_DIR.&quot;/_thumbnail/thumb_&quot;.strtolower($this-&amp;gt;Name).&quot;.png&quot;;&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	&lt;strong&gt;function&lt;/strong&gt; getThumbFilePath(){&lt;br /&gt;		return VIDEO_PATH.&quot;/_thumbnail/thumb_&quot;.strtolower($this-&amp;gt;Name).&quot;.png&quot;;&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;	&lt;strong&gt;function&lt;/strong&gt; getCMSThumbFileName(){&lt;br /&gt;		return VIDEO_DIR.&quot;/_thumbnail/CMSthumb_&quot;.strtolower($this-&amp;gt;Name).&quot;.png&quot;;&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	&lt;strong&gt;function&lt;/strong&gt; getCMSThumbFilePath(){&lt;br /&gt;		return VIDEO_PATH.&quot;/_thumbnail/CMSthumb_&quot;.strtolower($this-&amp;gt;Name).&quot;.png&quot;;&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	&lt;strong&gt;public function&lt;/strong&gt; CMSThumbnail() {&lt;br /&gt;		return $this-&amp;gt;generateCMSThumbnail();&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;	&lt;strong&gt;public function&lt;/strong&gt; getImage() {&lt;br /&gt;		return $this-&amp;gt;generateThumbnail();&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;	&lt;strong&gt;function&lt;/strong&gt; generateThumbnail(){&lt;br /&gt;		if(!file_exists($this-&amp;gt;getThumbFilePath())) {&lt;br /&gt;			$this-&amp;gt;getThumbnail($this-&amp;gt;stat(&quot;thumbnail_width&quot;), $this-&amp;gt;stat(&quot;thumbnail_height&quot;), $this-&amp;gt;getThumbFilePath());&lt;br /&gt;		}&lt;br /&gt;		return &quot;&amp;lt;img src=\&quot;&quot;.$this-&amp;gt;getThumbFileName().&quot;\&quot; title=\&quot;&quot;.$this-&amp;gt;Title.&quot;\&quot;&amp;gt;&quot;;&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;	&lt;strong&gt;function&lt;/strong&gt; generateCMSThumbnail() {&lt;br /&gt;		if(!file_exists($this-&amp;gt;getCMSThumbFilePath())) {&lt;br /&gt;			$this-&amp;gt;getThumbnail($this-&amp;gt;stat(&quot;cms_thumbnail_width&quot;), $this-&amp;gt;stat(&quot;cms_thumbnail_height&quot;), $this-&amp;gt;getCMSThumbFilePath());&lt;br /&gt;		}&lt;br /&gt;		&lt;br /&gt;		return &quot;&amp;lt;div style=\&quot;text-align:center;width: 100px;\&quot;&amp;gt;&amp;lt;a target=\&quot;_blank\&quot; href=\&quot;$this-&amp;gt;URL\&quot; title=\&quot;Download: $this-&amp;gt;URL\&quot;&amp;gt;&amp;lt;img src=\&quot;&quot;.$this-&amp;gt;getCMSThumbFileName().&quot;\&quot; alt=\&quot;&quot;.$this-&amp;gt;getCMSThumbFileName().&quot;\&quot; /&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;a style=\&quot;color: #0074C6;\&quot;target=\&quot;_blank\&quot; href=\&quot;$this-&amp;gt;URL\&quot; title=\&quot;Download: $this-&amp;gt;URL\&quot;&amp;gt;Download&amp;lt;/a&amp;gt;&amp;lt;/div&amp;gt;&quot;;&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	&lt;strong&gt;function&lt;/strong&gt; getThumbnail($width, $height, $filedest){&lt;br /&gt;		$videoFile = BASE_PATH.&quot;/&quot;.$this-&amp;gt;Filename;&lt;br /&gt;		if(file_exists($videoFile)){&lt;br /&gt;			$execthumb = FFMPEG_BIN.&quot; -i &quot;.$videoFile.&quot; -r 1 -s &quot;.$width.&quot;x&quot;.$height.&quot; -f image2pipe -vframes 1 -ss 00:00:01 &quot;.$filedest;&lt;br /&gt;			exec($execthumb);&lt;br /&gt;		}&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	&lt;strong&gt;function&lt;/strong&gt; getFlvFileName(){&lt;br /&gt;		return VIDEO_DIR.&quot;/_resampled/&quot;.&quot;flv_&quot;.strtolower($this-&amp;gt;Name).&quot;.flv&quot;;&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	&lt;strong&gt;function&lt;/strong&gt; getFlvFilePath(){&lt;br /&gt;		return VIDEO_PATH.&quot;/_resampled/flv_&quot;.strtolower($this-&amp;gt;Name).&quot;.flv&quot;;&lt;br /&gt;	}&lt;br /&gt;		&lt;br /&gt;	&lt;strong&gt;function&lt;/strong&gt; generateFlv(){&lt;br /&gt;		$videoFile = BASE_PATH.&quot;/&quot;.$this-&amp;gt;Filename;&lt;br /&gt;		$execvid =	FFMPEG_BIN.&quot; -i &quot;.$videoFile.&quot; -r 16 -ar 11025 -ab 32k -s cga -qscale 10 -y &quot;.$this-&amp;gt;getFlvFilePath();&lt;br /&gt;		exec($execvid);&lt;br /&gt;	}&lt;br /&gt;		&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;FlashVideo.php contains objects FlashVideo. This object is derived from the File object, so&amp;nbsp; this object has all the attributes and methods that are owned by the File object. In this FlashVideo object there are several variables used to configure the FlashVideo files:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;$thumbnail_width&lt;/strong&gt;, this variable is used to determine the width of the thumbnail images of video.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;$thumbnail_height&lt;/strong&gt;, this variable is used to determine the height of the thumbnail images of video.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;$cms_thumbnail_width&lt;/strong&gt;, this variable is used to determine the width of the thumbnail images of video on the admin page.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;$cms_thumbnail_width&lt;/strong&gt;, this variable is used to determine the height of the thumbnail image of video on the admin page.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;$allowedExtensions&lt;/strong&gt;, this variable contains an array of file extension to be uploaded. You can add other file extensions on these variables.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;$flvplayer&lt;/strong&gt;, this variable contains the relative path to the flv file player from silverstripe&amp;nbsp; directory.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you've made a second file, then run the command db/build/?flush=1 on silvertripe url to add FlashVideo objects into the silverstripe database structure. Later this object we can use on our pages.&lt;/p&gt;
&lt;h4&gt;&lt;strong&gt;Using FlashVideo Object&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;To use the FlashVideo object on silverstripe page, we can add a fields type FlashVideo like adding fields of type Image. If in the &lt;a href=&quot;http://www.sslearn.info/sslearn/creating-a-new-page-type/&quot;&gt;previous post&lt;/a&gt; in ArticlePage.php, we can add the following code:&lt;/p&gt;
&lt;pre&gt;    &lt;strong&gt;public static&lt;/strong&gt; $has_one = array(&lt;br /&gt;	'Picture' =&amp;gt; 'Image',&lt;br /&gt;&lt;strong&gt;	'Video' =&amp;gt; 'FlashVideo'&lt;/strong&gt;&lt;br /&gt;    );&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;We can use FileIFrameField for uploading video files on getCMSFields() method.&lt;/p&gt;
&lt;pre&gt;    &lt;strong&gt;function&lt;/strong&gt; getCMSFields() {&lt;br /&gt;       $fields = parent::getCMSFields();&lt;br /&gt;    &lt;br /&gt;       $fields-&amp;gt;addFieldToTab('Root.Content.Main', new CalendarDateField('Date'), 'Content');&lt;br /&gt;       $fields-&amp;gt;addFieldToTab(&quot;Root.Content.Main&quot;, new ImageField('Picture'));&lt;br /&gt;      &lt;strong&gt; $fields-&amp;gt;addFieldToTab(&quot;Root.Content.Main&quot;, new FileIFrameField('Video'));&lt;/strong&gt;&lt;br /&gt;            &lt;br /&gt;       return $fields;&lt;br /&gt;    }&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img class=&quot;center&quot; src=&quot;http://www.sslearn.info/sslearn/assets/Creating-FlashVideo-Object-on-Silverstripe/FlashVideo-Upload.png&quot; alt=&quot;FlashVideo Upload&quot; title=&quot;FlashVideo Upload&quot; width=&quot;573&quot; height=&quot;387&quot; /&gt;&lt;/p&gt;
&lt;p&gt;For our templates call variable of FlashVideo type ($Video) and placed on ArticlePage.ss as we want.&lt;/p&gt;
&lt;pre&gt;&amp;lt;h2&amp;gt;$Title&amp;lt;/h2&amp;gt;&lt;br /&gt;	&lt;br /&gt;$Picture&lt;br /&gt;&lt;strong&gt;$Video&lt;/strong&gt;&lt;br /&gt;$Content&lt;br /&gt;$Form&lt;br /&gt;$PageComments&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;Do not forget to do the command &lt;strong&gt;db/build/?flush=1&lt;/strong&gt;. After that will appear flv player on ArticlePage which will contain uploaded video.&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;center&quot; src=&quot;http://www.sslearn.info/sslearn/assets/Creating-FlashVideo-Object-on-Silverstripe/Page-With-Flv-Player.png&quot; alt=&quot;Page with Flv Player&quot; title=&quot;Page with Flv Player&quot; width=&quot;442&quot; height=&quot;542&quot; /&gt;&lt;/p&gt;
&lt;p&gt;You can download the source code files of the above FlashVideo objects &lt;a href=&quot;http://www.nanaz.net/images/upload/file/FlashVideo.zip&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;</description>
			<pubDate>Sun, 28 Mar 2010 06:48:44 -0500</pubDate>
			
			<guid>http://www.sslearn.info/sslearn/creating-flash-video-object-on-silverstripe/</guid>
		</item>
		
		<item>
			<title>Image Object on Silverstripe</title>
			<link>http://www.sslearn.info/sslearn/image-object-on-silverstripe/</link>
			<description>&lt;p&gt;If you read a post about &lt;a href=&quot;http://www.sslearn.info/sslearn/creating-a-new-page-type/&quot;&gt;Creating a New Page Type&lt;/a&gt;, I created a new type of pages that contain the image object. If we see inside of Class Articlepage there is a definition:&lt;/p&gt;
&lt;pre&gt;public static $has_one = array(&lt;br /&gt;	'Picture' =&amp;gt; 'Image'&lt;br /&gt;);&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;The meaning of the definition is each Articlepage will have a field of Image named Picture.&lt;/p&gt;
&lt;p&gt;Image is an object of silverstripe which is derived from the object file. All the attributes and methods contained in the object file will be owned by this object. The object image also has an additional method that is used to manipulate images for resizing.&lt;/p&gt;
&lt;h4&gt;&lt;strong&gt;Inputing Image File&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Image files can be input using a form object named ImageField. As ArticlePage.php there is one line of code in the method getCMSFields as follows:&lt;/p&gt;
&lt;pre&gt;$fields-&amp;gt;addFieldToTab(&quot;Root.Content.Main&quot;, new ImageField('Picture'));&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;The syntax above will display form fields to input the image file.&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;center&quot; src=&quot;http://www.sslearn.info/sslearn/assets/Image-Object-on-Silverstripe/_resampled/ResizedImage400151-ImageField.png&quot; alt=&quot;Image Field&quot; title=&quot;Image Field&quot; width=&quot;400&quot; height=&quot;151&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Each image file will be automatically uploaded to the directory assets/Uploads.&lt;/p&gt;
&lt;h4&gt;Image Object On the Templates&lt;/h4&gt;
&lt;p&gt;Image object also has a standard template that can be directly used in the template file (.ss). In the example template ArticlePage.ss, there is a code:&lt;/p&gt;
&lt;pre&gt;&amp;lt;div&amp;gt;$Picture&amp;lt;/div&amp;gt;&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;Where $Picture is Image Object, then on the HTML page will automatically become:&lt;/p&gt;
&lt;pre&gt;&amp;lt;img alt=&quot;engineeringrulerandpencil&quot; src=&quot;/sslearn/assets/Uploads/engineeringrulerandpencil.jpg&quot;&amp;gt;&lt;br /&gt;&lt;/pre&gt;
&lt;h4&gt;Resizing Image&lt;/h4&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;SetWidth&lt;/strong&gt;(width)&lt;br /&gt;Is a method to set the width of the image. With this method the height of the image will be set proportionally.&lt;br /&gt;How to use:&lt;br /&gt;
&lt;pre&gt;&amp;lt;div&amp;gt;$Picture.SetWidth(50)&amp;lt;/div&amp;gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SetHeight&lt;/strong&gt;(height)&lt;br /&gt;Is a method to set the height of the image. With this method the width of the image will be set proportionally.&lt;br /&gt;How to use:&lt;br /&gt;
&lt;pre&gt;&amp;lt;div&amp;gt;$Picture.SetHeight(50)&amp;lt;/div&amp;gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SetSize&lt;/strong&gt;(width, height)&lt;br /&gt;Is a method to set the image size based on width and height specified. This method will adjust the image in a padded conditions, where the image will remain on for proportional, but if the height or width are disproportionately the image will be filled with a white background to make the size fixed.&lt;br /&gt;How to use:&lt;br /&gt;
&lt;pre&gt;&amp;lt;div&amp;gt;&lt;br /&gt;	&amp;lt;% control Picture %&amp;gt;&lt;br /&gt;		&amp;lt;% control SetSize(100,50) %&amp;gt;&lt;br /&gt;			&amp;lt;img src=&amp;rdquo;$URL&amp;rdquo;/&amp;gt;&lt;br /&gt;		&amp;lt;% end_control %&amp;gt;&lt;br /&gt;	&amp;lt;% end_control %&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt; &lt;br /&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Beside to the above method there is also another method that can be used in the object image. You can read the documentation referred to in &lt;a href=&quot;http://doc.silverstripe.org/doku.php?id=image&quot; target=&quot;_blank&quot;&gt;http://doc.silverstripe.org/doku.php?id=image&lt;/a&gt;.&lt;/p&gt;</description>
			<pubDate>Thu, 25 Mar 2010 21:15:26 -0500</pubDate>
			
			<guid>http://www.sslearn.info/sslearn/image-object-on-silverstripe/</guid>
		</item>
		
		<item>
			<title>Creating Contact Page</title>
			<link>http://www.sslearn.info/sslearn/creating-contact-page/</link>
			<description>&lt;p&gt;At each web site, contact page (Contact Us) is one of the pages needed for site visitors to contact/comment to the creator's web. From the business side of this page must be made to accommodate the client desires. From this page also a business transaction can be starts.&lt;/p&gt;
&lt;p&gt;In silverstripe, we can create a contact page containing a form to be filled by the customer. Every customer who wants to contact or provide a message to the website must fill out a message on this form. Later messages are stored into the database or if it allows such messages will be immediately sent to the email the site creator. Page contact to be made in this post has a form that contains the field names, email, phone and message.&lt;/p&gt;
&lt;p&gt;Silverstripe has provide facilities page comments form, but is it a standard form. If we want another form we have to make our own. The way is easy and fast just like when we create pages in &lt;a href=&quot;http://www.sslearn.info/sslearn/creating-a-new-page-type/&quot;&gt;Creating New Page Type&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;This time we will create a new page type called ContactPage in which there will be a form called ContactForm. For that we need to create a page that is ContactPage and ContactForm. And also there will be a data object used to store data-entry in database named Contact.&lt;/p&gt;
&lt;h4&gt;ContactForm&lt;/h4&gt;
&lt;p&gt;Create a file ContactForm.php in the directory&amp;nbsp; mysite/code/&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;mysite/code/ContactForm.php&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&amp;lt;? &lt;br /&gt;class ContactForm extends Form { &lt;br /&gt;&lt;br /&gt;function __construct($controller, $name) { &lt;br /&gt;   $fields = new FieldSet( &lt;br /&gt;      new TextField(&quot;name&quot;, &quot;Name&quot;), &lt;br /&gt;      new TextField(&quot;Phone&quot;, &quot;Phone&quot;), &lt;br /&gt;      new EmailField(&quot;email&quot;, &quot;E-mail&quot;), &lt;br /&gt;      new TextareaField (&quot;message&quot;,&quot;Message&quot;) &lt;br /&gt;   ); &lt;br /&gt;&lt;br /&gt;   $actions = new FieldSet(new FormAction(&quot;sendContact&quot;, &quot;Send&quot;)); &lt;br /&gt;   $validator = new RequiredFields(&quot;name&quot;, &quot;email&quot;, &quot;message&quot;); &lt;br /&gt;&lt;br /&gt;   parent::__construct($controller, $name, $fields, $actions, $validator); &lt;br /&gt;} &lt;br /&gt;&lt;br /&gt;function forTemplate() { &lt;br /&gt;   return $this-&amp;gt;renderWith(array( &lt;br /&gt;      $this-&amp;gt;class, &lt;br /&gt;      'Form' &lt;br /&gt;   )); &lt;br /&gt;} &lt;br /&gt;&lt;br /&gt;function sendContact($data, $form) { &lt;br /&gt;} &lt;br /&gt;&lt;br /&gt;} &lt;br /&gt;?&amp;gt; &lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;ContactForm is a class derived from Form. Where the content of the initial fields of the form that will be made. The file also contains the action of ContactForm if the form submitted. Action named sendContact on ContactForm created using the ContactForm Class method. In this case action is empty. This meant that we could customize the action later. &lt;br /&gt;&lt;br /&gt;View for ContactForm will have stored on themes/themes1/templates/Includes directory. For that we need to create a file in that directory ContactForm.ss.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;themes/sslearn/templates/Includes/ContactForm.ss &lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&amp;lt;% if IncludeFormTag %&amp;gt; &lt;br /&gt;    &amp;lt;form $FormAttributes&amp;gt; &lt;br /&gt;&amp;lt;% end_if %&amp;gt; &lt;br /&gt;&amp;lt;% if Message %&amp;gt; &lt;br /&gt;   &amp;lt;p id=&quot;{$FormName}_error&quot; class=&quot;error $MessageType&quot;&amp;gt;$Message&amp;lt;/p&amp;gt; &lt;br /&gt;&amp;lt;% else %&amp;gt; &lt;br /&gt;   &amp;lt;p id=&quot;{$FormName}_error&quot; class=&quot;message $MessageType&quot; style=&quot;display: none&quot;&amp;gt;&amp;lt;/p&amp;gt; &lt;br /&gt;&amp;lt;% end_if %&amp;gt; &lt;br /&gt;&lt;br /&gt;&amp;lt;fieldset class=&quot;form&quot;&amp;gt; &lt;br /&gt;   &amp;lt;legend&amp;gt;$Legend&amp;lt;/legend&amp;gt; &lt;br /&gt;   &amp;lt;% control Fields %&amp;gt; &lt;br /&gt;       &amp;lt;label&amp;gt;&amp;lt;span&amp;gt;$title&amp;lt;/span&amp;gt; $Field&amp;lt;/label&amp;gt; &lt;br /&gt;   &amp;lt;% end_control %&amp;gt; &lt;br /&gt;   &amp;lt;div class=&quot;clear&quot;&amp;gt;&amp;lt;!-- --&amp;gt;&amp;lt;/div&amp;gt; &lt;br /&gt;&amp;lt;/fieldset&amp;gt; &lt;br /&gt;&lt;br /&gt;&amp;lt;% if Actions %&amp;gt; &lt;br /&gt;   &amp;lt;div class=&quot;send&quot;&amp;gt; &lt;br /&gt;   &amp;lt;% control Actions %&amp;gt; &lt;br /&gt;      $Field &lt;br /&gt;   &amp;lt;% end_control %&amp;gt; &lt;br /&gt;   &amp;lt;/div&amp;gt; &lt;br /&gt;&amp;lt;% end_if %&amp;gt; &lt;br /&gt;&amp;lt;% if IncludeFormTag %&amp;gt; &lt;br /&gt;   &amp;lt;/form&amp;gt; &lt;br /&gt;&amp;lt;% end_if %&amp;gt;&lt;br /&gt;&lt;/pre&gt;
&lt;h4&gt;ContactPage&lt;/h4&gt;
&lt;p&gt;Create a file ContactPage.php in the directory&amp;nbsp; mysite/code/&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;mysite/code/ContactPage.php&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&amp;lt;?php &lt;br /&gt;&lt;br /&gt;class ContactPage extends Page{ &lt;br /&gt;   public function getCMSFields() { &lt;br /&gt;      $fields = parent::getCMSFields(); &lt;br /&gt;      $contactEntry = new TableListField(&quot;contactEntry&quot;, &quot;Contact&quot;, array(&quot;name&quot;=&amp;gt;&quot;Name&quot;, &quot;phone&quot;=&amp;gt;&quot;Phone&quot;, &quot;email&quot;=&amp;gt;&quot;Email&quot;,&quot;message&quot;=&amp;gt;&quot;Message&quot;)); &lt;br /&gt;      $fields-&amp;gt;addFieldToTab(&quot;Root.Content.Contact&quot;, $contactEntry); &lt;br /&gt;      return $fields; &lt;br /&gt;   } &lt;br /&gt;&lt;br /&gt;} &lt;br /&gt;&lt;br /&gt;class ContactPage_Controller extends Page_Controller { &lt;br /&gt;   function ContactForm(){ &lt;br /&gt;      if(Session::get('ContactFormEntry')) { &lt;br /&gt;         Session::clear('ContactFormEntry'); &lt;br /&gt;         return &quot;Your message has been sent&quot;; &lt;br /&gt;      } &lt;br /&gt;&lt;br /&gt;      $form = new ContactForm($this, &quot;ContactForm&quot;); &lt;br /&gt;      return $form; &lt;br /&gt;   } &lt;br /&gt;&lt;br /&gt;   function sendContact($data,$form) { &lt;br /&gt;      Session::set('ContactFormEntry', true); &lt;br /&gt;      $Contact = new Contact; &lt;br /&gt;      $form-&amp;gt;saveInto($Contact); &lt;br /&gt;      $Contact-&amp;gt;write(); &lt;br /&gt;      Director::redirectBack(); &lt;br /&gt;   } &lt;br /&gt;&lt;br /&gt;} &lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;ContactPage is a type of page that will be used to display ContactForm. ContactPage controller has a method to display ContactForm. From controller method, ContactPage also containing sendContact controller commands of the form. In sendContact method, data storage will be made into the data object Contact. For that we'll also have to create data objects Contact. Then after contact has been saved to database we can return to the previous page with instructions Director::redirectBack().&lt;/p&gt;
&lt;p&gt;In the file ContactPage.php we see the contents getCMSField method more or less as follows:&lt;/p&gt;
&lt;pre&gt;public function getCMSFields() { &lt;br /&gt;	$fields = parent::getCMSFields(); &lt;br /&gt;	$contactEntry = new TableListField(&quot;contactEntry&quot;, &quot;Contact&quot;, array(&quot;name&quot;=&amp;gt;&quot;Name&quot;, &quot;phone&quot;=&amp;gt;&quot;Phone&quot;, &quot;email&quot;=&amp;gt;&quot;Email&quot;,&quot;message&quot;=&amp;gt;&quot;Message&quot;)); &lt;br /&gt;	$fields-&amp;gt;addFieldToTab(&quot;Root.Content.Contact&quot;, $contactEntry); &lt;br /&gt;	return $fields; &lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;In this method, we use an object TableListField to be used to display the contents of the Contact data objects that are used to store data from ContactForm entry.&lt;/p&gt;
&lt;p&gt;After creating the file we have to make ContactPage.php view the contents ContactPage.ss approximately as follows:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;themes/sslearn/templates/ContactPage.ss &lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&amp;lt;html&amp;gt; &lt;br /&gt;   &amp;lt;head&amp;gt; &lt;br /&gt;   &amp;lt;title&amp;gt;Themes Silverstripe 1&amp;lt;/title&amp;gt; &lt;br /&gt;   &amp;lt;/head&amp;gt; &lt;br /&gt;   &amp;lt;body&amp;gt; &lt;br /&gt;      &amp;lt;ul&amp;gt; &lt;br /&gt;      &amp;lt;% control Menu(1) %&amp;gt; &lt;br /&gt;         &amp;lt;li&amp;gt; &amp;lt;a href=&quot;$Link&quot;&amp;gt;$MenuTitle&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt; &lt;br /&gt;      &amp;lt;% end_control %&amp;gt; &lt;br /&gt;      &amp;lt;/ul&amp;gt; &lt;br /&gt;      &amp;lt;div&amp;gt; &lt;br /&gt;         &amp;lt;h1&amp;gt;$Title&amp;lt;/h1&amp;gt; &lt;br /&gt;         $Content &lt;br /&gt;         &lt;strong&gt;$ContactForm&lt;/strong&gt; &lt;br /&gt;      &amp;lt;/div&amp;gt; &lt;br /&gt;   &amp;lt;/body&amp;gt; &lt;br /&gt;&amp;lt;/html&amp;gt; &lt;br /&gt;&lt;/pre&gt;
&lt;h4&gt;Contact Data Object&lt;/h4&gt;
&lt;p&gt;Contact data object used to store data entry from ContactForm action. This data object that will represent the database. For making this Contact data object we need to make a contact.php file whose contents form a class named Contact derived from the DataObject class. These files are stored in the directory mysite / code / with following contents:&lt;/p&gt;
&lt;pre&gt;&amp;lt;?php &lt;br /&gt;&lt;br /&gt;class Contact extends DataObject{ &lt;br /&gt;&lt;br /&gt;	static $db = array( &lt;br /&gt;		'name' =&amp;gt; 'Varchar', &lt;br /&gt;		'phone' =&amp;gt; 'Varchar', &lt;br /&gt;		'email' =&amp;gt; 'Varchar', &lt;br /&gt;		'message' =&amp;gt; 'Text' &lt;br /&gt;	); &lt;br /&gt;&lt;br /&gt;} &lt;br /&gt;?&amp;gt; &lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;In the Contact class will have an array variable named $db. The contents of this variable is array containing field definition in the database that will be used to store data in the entry on ContactForm we have previously made. The name of his field-adjusted to the form that was created.&lt;/p&gt;
&lt;p&gt;The last stage before we use this contact form is to flush the database to build a database and silverstripe form and page design that we make. Way by typing ttp://localhost/sslearn/db/build/?flush=1 in your browser.&lt;/p&gt;
&lt;p&gt;Next ContactPage page type will appear in the combo box when we will add a new page in the admin page of our Silverstripe CMS.&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;center&quot; src=&quot;http://www.sslearn.info/sslearn/assets/Creating-Contact-Page/ContactPage.png&quot; alt=&quot;ContactPage&quot; title=&quot;ContactPage&quot; width=&quot;191&quot; height=&quot;191&quot; /&gt;&lt;/p&gt;
&lt;p&gt;And also the contact tab will appear on the form on the contact page CMS to see anyone who has entry our contact data. This tab will contain the contact tablelistfield we have previously defined.&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;center&quot; src=&quot;http://www.sslearn.info/sslearn/assets/Creating-Contact-Page/ContactTab.png&quot; alt=&quot;ContactTab&quot; title=&quot;ContactTab&quot; width=&quot;480&quot; height=&quot;188&quot; /&gt;&lt;/p&gt;
&lt;p&gt;The way is easy enough. Please try by yourself, if there is a problem please give comments.&lt;/p&gt;</description>
			<pubDate>Wed, 24 Mar 2010 00:58:51 -0500</pubDate>
			
			<guid>http://www.sslearn.info/sslearn/creating-contact-page/</guid>
		</item>
		
		<item>
			<title>Installing Mod_Rewrite on Apache</title>
			<link>http://www.sslearn.info/sslearn/installing-mod-rewrite-on-apache/</link>
			<description>&lt;p&gt;Mod_rewrite is used to change the URL using the commands rewriting engine (based on regex parser) is requested on the fly (directly). To use this module the Apache minimum version required is Apache 1.2 or latest version. You can install as a module mod_rewrite on your Apache webserver.&lt;/p&gt;
&lt;p&gt;Before you install this module first checks whether the module is already installed by using phpinfo() if you are using php as a web programming. Loaded Modules section will appear modules that already installed, look for the words mod_rewrite, if exists you do not need to install the module, if not then prepared to install it.&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;center&quot; src=&quot;http://www.sslearn.info/sslearn/assets/Installing-Mod_Rewrite-on-Apache/_resampled/ResizedImage400210-apachehandlers.png&quot; alt=&quot;Apache Handlers&quot; title=&quot;Apache Handlers&quot; width=&quot;400&quot; height=&quot;210&quot; /&gt;&lt;/p&gt;
&lt;p&gt;The author uses Apache/2.2.12, PHP/5.2.10, Apache server bundle with Ubuntu Linux as operating system. To install this module looking for Apache httpd.conf file found in &quot;/etc/apache2&quot;. Open the file with your preferred editor, notepad, gEdit, vim, nano, etc.. Find rows that contain word mod_rewrite.&amp;nbsp;&lt;/p&gt;
&lt;pre&gt;# LoadModule rewrite_module modules/mod_rewrite.so&lt;/pre&gt;
&lt;p&gt;Then remove the sign # in line to become:&lt;/p&gt;
&lt;pre&gt;LoadModule rewrite_module modules/mod_rewrite.so&lt;/pre&gt;
&lt;p&gt;Save the httpd.conf file and then restart your Apache, the mod_rewrite module is ready for use. To ensure re-check with the phpinfo().&lt;/p&gt;
&lt;p&gt;To make the file is easy, open your editor and save as the name &quot;.htaccess&quot;.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you are hosting to a provider usually we are not allowed to use the file type &quot;.htaccess&quot;, then ask your provider to allow it. If you are using in the test localserver the configuration file is in httpd.conf, find the location of the directory where you placed the files of your web.&lt;/p&gt;
&lt;pre&gt;        &amp;lt;Directory /var/www/&amp;gt;
                Options Indexes FollowSymLinks MultiViews
                AllowOverride all # &lt;strong&gt;You must change&lt;/strong&gt;
                Order allow,deny
                allow from all
        &amp;lt;/Directory&amp;gt;&lt;span style=&quot;white-space: normal;&quot;&gt;
&lt;/span&gt;&lt;/pre&gt;
&lt;div&gt;&lt;br /&gt;&lt;/div&gt;
&lt;p&gt;This section is to restrict the use of &quot;.htaccess&quot; on the server, for security settings are at &quot;None&quot; in this case to menggunakani mod_rewrite then turned into &quot;all&quot;.&lt;/p&gt;
&lt;p&gt;After all the preparation has been done so mod_rewrite is ready to use. Now open your .htaccess file and write the following code then save.&lt;/p&gt;
&lt;pre&gt;Options +FollowSymLinks 
RewriteEngine On 
RewriteRule google http://www.google.com/? [R,L]&lt;/pre&gt;
&lt;p&gt;Call your browser and type localhost/google or www.yourdomain.com/google, if the URL directly redirect to google.com means your mod_rewrite is running.&lt;/p&gt;</description>
			<pubDate>Sun, 21 Mar 2010 20:35:16 -0500</pubDate>
			
			<guid>http://www.sslearn.info/sslearn/installing-mod-rewrite-on-apache/</guid>
		</item>
		
		<item>
			<title>Creating a New Page Type</title>
			<link>http://www.sslearn.info/sslearn/creating-a-new-page-type/</link>
			<description>&lt;p&gt;The first time when we &lt;a href=&quot;http://www.sslearn.info/sslearn/how-to-install-silverstripe/&quot; title=&quot;How to Install Silverstripe&quot;&gt;install silverstripe&lt;/a&gt;, silverstripe has provided some type of standard pages that can we use. These page types are:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Page&lt;/strong&gt;: this is the type of standard pages for each page shown.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ErrorPage&lt;/strong&gt;: This page is a page to display a customizable error conditions. For example we can use this type to create 404 pages (page not found) with a layout according to which we want.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;RedirectorPage&lt;/strong&gt;: This page is a page to redirect (move to another page), whether it is in our web or those outside of our web.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;VirtualPage&lt;/strong&gt;: same as Redirector page but only devoted to the existing pages on our website only, with different link from the destination page.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Apart from these four types of pages we can also create our own types of pages in accordance with our needs. Suppose we want to create a page whose content type consists of the title, date, pictures and content that we give the name of the type is &lt;strong&gt;ArticlePage&lt;/strong&gt;. The way is easy and it not takes a lot of time.&lt;/p&gt;
&lt;p&gt;Making a page type on silverstripe refer to the concept of &lt;a href=&quot;http://www.sslearn.info/sslearn/knowing-silverstripe-mvc/&quot; title=&quot;Knowing Silverstripe MVC&quot;&gt;MVC development framework&lt;/a&gt;. Where on this concept of a type of page is always going to have a component Model, View and Controller. For that, ArticlePage that will be created will have all three of these components.&lt;/p&gt;
&lt;h4&gt;Model and Controller&lt;/h4&gt;
&lt;p&gt;Model and Controller in silverstripe to a type of pages stored in a file that is located in the mysite/code/ directory&amp;nbsp; and have the extension .php. If we want to make a type named ArticlePage then we must create a php file named ArticlePage.php in that directory with the following contents:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;mysite/code/ArticlePage.php&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;&amp;lt;?&lt;strong&gt;php&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;class&lt;/strong&gt; ArticlePage &lt;strong&gt;extends&lt;/strong&gt; Page { // Model&lt;br /&gt;    &lt;strong&gt;static&lt;/strong&gt; $db = array(&lt;br /&gt;       'Date' =&amp;gt; 'Date',&lt;br /&gt;    );&lt;br /&gt;    &lt;strong&gt;public&lt;/strong&gt; &lt;strong&gt;static&lt;/strong&gt; $has_one = array(&lt;br /&gt;        'Picture' =&amp;gt; 'Image',&lt;br /&gt;    );    &lt;br /&gt;    &lt;strong&gt;function&lt;/strong&gt; getCMSFields() {&lt;br /&gt;       $fields = parent::getCMSFields();&lt;br /&gt;    &lt;br /&gt;       $fields-&amp;gt;addFieldToTab('Root.Content.Main', new CalendarDateField('Date'), 'Content');&lt;br /&gt;       $fields-&amp;gt;addFieldToTab(&quot;Root.Content.Main&quot;, new ImageField('Picture'));&lt;br /&gt;            &lt;br /&gt;       &lt;strong&gt;return&lt;/strong&gt; $fields;&lt;br /&gt;    }    &lt;br /&gt;}&lt;br /&gt;/* controller */&lt;br /&gt;&lt;strong&gt;class&lt;/strong&gt; ArticlePage_Controller &lt;strong&gt;extends&lt;/strong&gt; Page_Controller {&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;The model and controller at silverstripe using Object-oriented programming concepts, where each page will have a hierarchy like the image below:&lt;/p&gt;
&lt;p&gt;&lt;img class=&quot;center&quot; src=&quot;http://www.sslearn.info/sslearn/assets/Creating-a-new-Page-Type/_resampled/ResizedImage440255-Inheritance.png&quot; alt=&quot;Inheritance&quot; title=&quot;Inheritance&quot; width=&quot;440&quot; height=&quot;255&quot; /&gt;&lt;/p&gt;
&lt;p&gt;So that at each new page type for it must be the child of Page. In his own page type is already providing data fields in the form like titles and content, so that it automatically will also be included in each type of page that is derived from the type of this page. We just need to make two additional fields of date and pictures. So the controller file Articlepage we need to add a variable like:&lt;/p&gt;
&lt;pre&gt;    &lt;strong&gt;static&lt;/strong&gt; $db = array(&lt;br /&gt;       'Date' =&amp;gt; 'Date'&lt;br /&gt;    );&lt;br /&gt;    &lt;strong&gt;public static&lt;/strong&gt; $has_one = array(&lt;br /&gt;        'Picture' =&amp;gt; 'Image'&lt;br /&gt;    );    &lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;Static $db is a database variable that will be generated by silverstripe, the contents contain an array of fields. Here the static $db we added a Date field which the type of the field also named Date. If you want to add any other fields you can add yourself to the field names at $db variable with the type of data. List of other data types you can see on URL &lt;a href=&quot;http://doc.silverstripe.com/doku.php?id=data-types&quot; target=&quot;_blank&quot; title=&quot;Data-types&quot;&gt;http://doc.silverstripe.com/doku.php?id=data-types&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;You may wonder why the $db variable is not directly include Picture with Image type? Actually the silverstripe image/file is stored using a separate table with the table of page. Because of that, if we want to use the image/file on our pages, we need relating our page to the table image/file. Here we use the $has_one variable which means every ArticlePage have one Picture with the type called Image.&lt;/p&gt;
&lt;p&gt;After declaring the field we must add these fields into the CMS form. GetCMSFields() method is the method to used to display the field in the CMS. For that we need to override this method to display the form accordance with the field that we have declare before.&lt;/p&gt;
&lt;h4&gt;The View&lt;/h4&gt;
&lt;p&gt;Furthermore, we must create a view of the ArticlePage pages. Make a file called ArticlePage.ss which is stored in the directory templates/ of our themes directory. The example content of the file may like this:&lt;/p&gt;
&lt;pre&gt;&amp;lt;html&amp;gt;&lt;br /&gt;    &amp;lt;head&amp;gt;&lt;br /&gt;        &amp;lt;title&amp;gt;Themes Silverstripe 1&amp;lt;/title&amp;gt;&lt;br /&gt;    &amp;lt;/head&amp;gt;&lt;br /&gt;    &amp;lt;body&amp;gt;&lt;br /&gt;    &amp;lt;ul&amp;gt;&lt;br /&gt;        &amp;lt;% control Menu(1) %&amp;gt;&lt;br /&gt;        &amp;lt;li&amp;gt;&amp;lt;a href=&quot;$Link&quot;&amp;gt;$MenuTitle&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;        &amp;lt;% end_control %&amp;gt;&lt;br /&gt;    &amp;lt;/ul&amp;gt;&lt;br /&gt;    &amp;lt;div&amp;gt;&lt;br /&gt;        &amp;lt;h1&amp;gt;$Title&amp;lt;/h1&amp;gt;&lt;br /&gt;        &amp;lt;div&amp;gt;Date : $Date.nice&amp;lt;/div&amp;gt;&lt;br /&gt;        &amp;lt;div&amp;gt;$Picture&amp;lt;/div&amp;gt;&lt;br /&gt;        $Content&lt;br /&gt;        $Form&lt;br /&gt;    &amp;lt;/div&amp;gt;&lt;br /&gt;    &amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;If the Model, View and Controller is completed, access db/build/?flush=1 page in your browser. Later on the admin page will appear Article Page for the choice when making the page. The Article Page will show the form with the fields we have set.&lt;/p&gt;</description>
			<pubDate>Sat, 20 Mar 2010 00:53:24 -0500</pubDate>
			
			<guid>http://www.sslearn.info/sslearn/creating-a-new-page-type/</guid>
		</item>
		

	</channel>
</rss>
