<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4736082337228328098</id><updated>2011-04-21T12:41:39.237-07:00</updated><title type='text'>Model View Controller development with PHP and FUSE</title><subtitle type='html'>Real world examples of working with the Fuse MVC framework for PHP. Model View Controller has emerged as the most robust, scalable approach to web development, and has been popularized by other frameworks such as Ruby on Rails and CakePHP. Fuse takes cues from both of those frameworks and packages it in an intuitive, easy to learn system.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://fusephpmvc.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4736082337228328098/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://fusephpmvc.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Jim Keller</name><uri>http://www.blogger.com/profile/04379106179273487649</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>6</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4736082337228328098.post-2526104978559216604</id><published>2008-07-27T20:21:00.000-07:00</published><updated>2008-07-28T08:15:21.954-07:00</updated><title type='text'>Automatic PHP SQL Searching with Fuse</title><content type='html'>The FuseDataController has powerful data search capabilities built right in. All you have to do is set up inputs in your view that are named as "search_field_name" (a Helper for this is in the works), then mark those fields as searchable in your controller. Below is an example from a project I worked on where we had to search products by various criteria&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;ProductController.class.php&lt;/span&gt;&lt;br /&gt;&lt;pre class="controller_code"&gt;&lt;br /&gt;FUSE::Require_class('AppControl/FuseDataController');&lt;br /&gt;class ProductController extends FuseDataController {&lt;br /&gt;&lt;br /&gt;        public $paginate = array( 'items_per_page' =&gt; 10, 'pages_linked_through_uri' =&gt; false );&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; public $search_fields = array( &lt;br /&gt;  'product_title' =&gt; array('filter_type' =&gt; 'like' ),&lt;br /&gt;  'product_number' =&gt; array('filter_type' =&gt; 'wildcard_right' ), &lt;br /&gt;  'product_customer_number' =&gt; array( 'filter_type' =&gt; 'wildcard_right', 'db_field' =&gt; 'customer_assignments.customer_assignment_part_number'),&lt;br /&gt;  'product_factory_number' =&gt; array( 'filter_type' =&gt; 'wildcard_right'), &lt;br /&gt;  'product_type_id' =&gt; array( 'filter_type' =&gt; 'direct')&lt;br /&gt; );&lt;br /&gt;&lt;br /&gt;        // We need to join the customer_assignments table, but only&lt;br /&gt;        // if a product_customer_number was specified &lt;br /&gt;        //&lt;br /&gt; public $search_settings = array( &lt;br /&gt;   'join_if' =&gt; array( 'product_customer_number' =&gt; 'LEFT JOIN customer_assignments ON customer_assignments.product_id = products.product_id')&lt;br /&gt; &lt;br /&gt; );&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Supported options for filter_type are:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;fulltext&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;greater_than&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;greater_than_equal&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;in&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;less_than&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;direct&lt;/span&gt; (will search using a direct comparison, e.g. myfield=34)&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;like&lt;/span&gt; (default - where myfield like '%value%')&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;like_insensitive&lt;/span&gt; (case insensitive version of like)&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;wildcard_left&lt;/span&gt; (myfield like '%value')&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;wildcard_left_i&lt;/span&gt; (myfield like '%value' - case insensitive)&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;wildcard_right&lt;/span&gt; (myfield like 'value%')&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;wildcard_right_i&lt;/span&gt; (myfield like 'value%' - case insensitive)&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;date_interval&lt;/span&gt; (expects dropdowns called search_mydatefield_month_to, _day_to, year_to, _day_from, _month_from, _year_from)&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;views/Product/Product-Search.tmpl&lt;/span&gt;&lt;br /&gt;&lt;pre class="view_code"&gt;&lt;br /&gt;&amp;lt;script language="Javascript" type="text/javascript" src="&amp;lt;{SITE_BASE_URI}&amp;gt;/script/DomControl.js"&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&amp;lt;script language="Javascript" type="text/javascript" src="&amp;lt;{SITE_BASE_URI}&amp;gt;/script/Pagination.js"&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;{HTML/ListHelper::Pagination_setup('Product')}&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;form action="?" method="get"&amp;gt;&lt;br /&gt;&amp;lt;input type="hidden" name="start_search" value="1" /&amp;gt;&lt;br /&gt;&amp;lt;fieldset style="margin-top: 12px;"&amp;gt;&lt;br /&gt;&amp;lt;legend&amp;gt;Product Search&amp;lt;/legend&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;div class="input_container"&amp;gt;&lt;br /&gt;&amp;lt;div class="form_label"&amp;gt;Product Name:&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div class="form_input"&amp;gt;&amp;lt;input id="textbox_search_product_name" type="text" name="search_product_name" /&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;div class="input_container"&amp;gt;&lt;br /&gt;&amp;lt;div class="form_label"&amp;gt;Customer Part Number:&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div class="form_input"&amp;gt;&amp;lt;input id="textbox_search_product_customer_number" type="text" name="search_product_customer_number" /&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;div class="input_container"&amp;gt;&lt;br /&gt;&amp;lt;div class="form_label"&amp;gt;Factory Part Number:&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div class="form_input"&amp;gt;&amp;lt;input id="textbox_search_factory_part_number" type="text" name="search_product_factory_part_number" /&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;div class="input_container"&amp;gt;&lt;br /&gt;&amp;lt;div class="form_label"&amp;gt;Product Type:&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div class="form_input"&amp;gt;&amp;lt;{HTML/FormOptionsHelper::Select_all('ProductType', 'name', 'id', array('empty_value_text' =&amp;gt; '-Any-', 'input_name' =&amp;gt; 'search_product_type_id'))}&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;div style="margin-top: 5px; clear:both; text-align:center;"&amp;gt;&lt;br /&gt;&amp;lt;input type="submit" value="Search" /&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/fieldset&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;{IF search_is_active}&amp;gt;&lt;br /&gt;&amp;lt;fieldset style="margin-top: 12px;"&amp;gt;&lt;br /&gt;&amp;lt;legend&amp;gt;Results&amp;lt;/legend&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;div id="page_links" style="float:right; margin-top: 5px;"&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;{HTML/ListHelper::Pagination_generate('Product')}&amp;gt;&lt;br /&gt;&amp;lt;div class="clearer"&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div style="margin-top: 4px;"&amp;gt;&lt;br /&gt;&amp;lt;table class="list_table" style="width:100%;"&amp;gt;&lt;br /&gt;  &amp;lt;tr&amp;gt;&lt;br /&gt;    &amp;lt;th style="width: 120px;"&amp;gt;Picture&amp;lt;/th&amp;gt;&lt;br /&gt;    &amp;lt;th colspan=""&amp;gt;Title&amp;lt;/th&amp;gt;&lt;br /&gt;    &amp;lt;th colspan=""&amp;gt;Details&amp;lt;/th&amp;gt;&lt;br /&gt;    &amp;lt;th colspan=""&amp;gt;Description&amp;lt;/th&amp;gt;&lt;br /&gt;   &amp;lt;/tr&amp;gt;&lt;br /&gt;  &amp;lt;{ITERATOR products}&amp;gt;&lt;br /&gt;  &amp;lt;tr style="cursor:pointer;" onclick="document.location.href='&amp;lt;{$_SITE_BASE_URI}&amp;gt;/product/view/&amp;lt;{id}&amp;gt;'" class="row&amp;lt;{HTML/ListHelper::Cycle('1','2')}&amp;gt;"&amp;gt;&lt;br /&gt;       &amp;lt;td&amp;gt;&amp;lt;img src="&amp;lt;{$_SITE_BASE_URI}&amp;gt;/photos/products/&amp;lt;{print(File/FilePath::Range_dir_name( id ))}&amp;gt;/thumb_browse/&amp;lt;{photo_filename}&amp;gt;" /&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;       &amp;lt;td style="width: 140px;"&amp;gt;&amp;lt;{title}&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;     &amp;lt;td style="width: 140px;"&amp;gt;&amp;lt;{print(str_replace('|', '&amp;lt;br /&amp;gt;', product_detail_string) )}&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;     &amp;lt;td&amp;gt;&amp;lt;{Output/OutputHelper::Substr_echo( description, 0, 300, array('more_link' =&amp;gt; '...') ) }&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;  &amp;lt;/tr&amp;gt;&lt;br /&gt;  &amp;lt;{/ITERATOR}&amp;gt;&lt;br /&gt;&amp;lt;/table&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/fieldset&amp;gt;&lt;br /&gt;&amp;lt;{/IF}&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Note: by default, the search checks $_GET for the search input values. To change to post, add to your $search_settings member as follows:&lt;br /&gt;&lt;br /&gt;&lt;pre class="controller_code"&gt;&lt;br /&gt;public $search_settings = array( 'form_submit_method' =&gt; 'post' )&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4736082337228328098-2526104978559216604?l=fusephpmvc.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://fusephpmvc.blogspot.com/feeds/2526104978559216604/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4736082337228328098&amp;postID=2526104978559216604' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4736082337228328098/posts/default/2526104978559216604'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4736082337228328098/posts/default/2526104978559216604'/><link rel='alternate' type='text/html' href='http://fusephpmvc.blogspot.com/2008/07/automatic-php-sql-searching-with-fuse.html' title='Automatic PHP SQL Searching with Fuse'/><author><name>Jim Keller</name><uri>http://www.blogger.com/profile/04379106179273487649</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4736082337228328098.post-7449992356376360572</id><published>2008-07-19T11:42:00.000-07:00</published><updated>2008-07-19T11:51:40.869-07:00</updated><title type='text'>Setting form requirements for a FuseDataController</title><content type='html'>The below code is taken from an application I'm working on where customer service representatives can track calls, which are linked to contacts. I wanted to give the representatives the ability to add a contact at the same time as a call, if they choose. The form requirements below require that a call[datetime_date] always be set, and that the contact[f_name], etc... are set *if* the form input add_new_contact has a value of 1. It also forces call[datetime_date] to be in mm/dd/YYYY format using the 'regexp' option&lt;br /&gt;&lt;br /&gt;&lt;pre class="controller_code" style="height: 300px;"&gt;&lt;br /&gt; public $form_requirements = array( &lt;br /&gt;  'contact[f_name]' =&gt; &lt;br /&gt;  array( 'friendly_name' =&gt; 'the contact\'s first name', &lt;br /&gt;   'required_if' =&gt; array('add_new_contact' =&gt; array('value' =&gt; 1, 'type' =&gt; 'textbox' )) ),&lt;br /&gt;&lt;br /&gt;         'contact[l_name]' =&gt; &lt;br /&gt;  array( 'friendly_name' =&gt; 'the contact\'s last name', &lt;br /&gt;       'required_if' =&gt; array('add_new_contact' =&gt; array('value' =&gt; 1, 'type' =&gt; 'textbox' )) ),&lt;br /&gt;   &lt;br /&gt;  'contact[address1]' =&gt; &lt;br /&gt;  array( 'friendly_name' =&gt; 'the first line of the address', &lt;br /&gt;   'required_if' =&gt; array('add_new_contact' =&gt; array('value' =&gt; 1, 'type' =&gt; 'textbox' )) ),&lt;br /&gt;&lt;br /&gt;  'contact[city]' =&gt; &lt;br /&gt;   array( 'friendly_name' =&gt; 'a city',&lt;br /&gt;    'required_if' =&gt; array('add_new_contact' =&gt; array('value' =&gt; 1, 'type' =&gt; 'textbox' )) ),&lt;br /&gt;  &lt;br /&gt;                'contact[zip_code]' =&gt; &lt;br /&gt;   array( 'friendly_name' =&gt; 'a zip code',&lt;br /&gt;    'required_if' =&gt; array('add_new_contact' =&gt; array('value' =&gt; 1, 'type' =&gt; 'textbox' )) ),&lt;br /&gt;   &lt;br /&gt;         'call[datetime_date]' =&gt; &lt;br /&gt;  array( 'friendly_name' =&gt; 'the call date', &lt;br /&gt;  'regexp' =&gt; '/\d{2}\/\d{2}\/\d{4}/' )&lt;br /&gt; );&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In my controller, I used a version of &lt;a href="http://fusephpmvc.blogspot.com/2008/07/adding-to-multiple-tables-in-from-one.html"&gt;adding to multiple tables from one form&lt;/a&gt; to add both the contact and the call.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4736082337228328098-7449992356376360572?l=fusephpmvc.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://fusephpmvc.blogspot.com/feeds/7449992356376360572/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4736082337228328098&amp;postID=7449992356376360572' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4736082337228328098/posts/default/7449992356376360572'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4736082337228328098/posts/default/7449992356376360572'/><link rel='alternate' type='text/html' href='http://fusephpmvc.blogspot.com/2008/07/setting-form-requirements-for.html' title='Setting form requirements for a FuseDataController'/><author><name>Jim Keller</name><uri>http://www.blogger.com/profile/04379106179273487649</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4736082337228328098.post-350566510673820697</id><published>2008-07-09T09:19:00.000-07:00</published><updated>2008-07-09T09:23:21.923-07:00</updated><title type='text'>Setting a date or datetime field to current date or time</title><content type='html'>If you need a datetime or datetime field to reflect the current date and/or time when adding, use the following in your controller:&lt;br /&gt;&lt;br /&gt;&lt;pre class="controller_code"&gt;&lt;br /&gt;public function before_add() {&lt;br /&gt;&lt;br /&gt;   //assuming our datetime field is called 'entry_datetime'&lt;br /&gt;   $this-&gt;model-&gt;set_db_param_type( 'entry_datetime', 'function' ); //tell the model that we don't want a literal 'NOW()' inserted&lt;br /&gt;   $this-&gt;model-&gt;entry_datetime = 'NOW()';&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;You can also add the same code to before_edit() if you need the same functionality when editing&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4736082337228328098-350566510673820697?l=fusephpmvc.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://fusephpmvc.blogspot.com/feeds/350566510673820697/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4736082337228328098&amp;postID=350566510673820697' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4736082337228328098/posts/default/350566510673820697'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4736082337228328098/posts/default/350566510673820697'/><link rel='alternate' type='text/html' href='http://fusephpmvc.blogspot.com/2008/07/setting-date-or-datetime-field-to.html' title='Setting a date or datetime field to current date or time'/><author><name>Jim Keller</name><uri>http://www.blogger.com/profile/04379106179273487649</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4736082337228328098.post-3820154940488701853</id><published>2008-07-08T08:04:00.000-07:00</published><updated>2008-07-08T08:13:07.414-07:00</updated><title type='text'>Using a helper to count items in an iterator</title><content type='html'>today the example is for a site that organizes web links and associates them with tags. In order to count the tags while listing data, we do something like this:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;views/Link/Link-List.tmpl&lt;/span&gt;&lt;br /&gt;&lt;pre class="view_code"&gt;&lt;br /&gt;&amp;lt;table&amp;gt;&lt;br /&gt;  &amp;lt;tr&amp;gt;&lt;br /&gt;    &amp;lt;th&amp;gt;URL&amp;lt;/th&amp;gt;&lt;br /&gt;    &amp;lt;th&amp;gt;Tags&amp;lt;/th&amp;gt;&lt;br /&gt;  &amp;lt;/tr&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;{ITERATOR links}&amp;gt;&lt;br /&gt;  &amp;lt;tr&amp;gt;&lt;br /&gt;    &amp;lt;td&amp;gt;&amp;lt;{url}&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;    &amp;lt;td&amp;gt;&lt;br /&gt;        &amp;lt;{IF (LinkHelper::Count_tags_by_link_id(id) &amp;gt; 0)}&amp;gt;&lt;br /&gt;        &amp;lt;{ITERATOR get_tags()}&amp;gt;&lt;br /&gt;          &amp;lt;{name}&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;        &amp;lt;{/ITERATOR}&amp;gt;&lt;br /&gt;        &amp;lt;{ELSE}&amp;gt;&lt;br /&gt;        (none)&lt;br /&gt;        &amp;lt;{/IF}&amp;gt;&lt;br /&gt;    &amp;lt;/td&amp;gt;&lt;br /&gt;  &amp;lt;/tr&amp;gt;&lt;br /&gt;  &amp;lt;{/ITERATOR}&amp;gt;&lt;br /&gt;&amp;lt;/table&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;include/LinkHelper.class.php&lt;/span&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;public static function Count_tags_by_link_id( $link_id ) {&lt;br /&gt;&lt;br /&gt;  FUSE::Require_model( 'Link' );&lt;br /&gt;  &lt;br /&gt;  $link = new Link();&lt;br /&gt;  $link-&gt;id = $link_id;&lt;br /&gt;&lt;br /&gt;  return $link-&gt;tags-&gt;count_all();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;models/Link.class.php&lt;/span&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;public function get_tags() {&lt;br /&gt;  return $this-&gt;tags-&gt;fetch_all();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4736082337228328098-3820154940488701853?l=fusephpmvc.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://fusephpmvc.blogspot.com/feeds/3820154940488701853/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4736082337228328098&amp;postID=3820154940488701853' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4736082337228328098/posts/default/3820154940488701853'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4736082337228328098/posts/default/3820154940488701853'/><link rel='alternate' type='text/html' href='http://fusephpmvc.blogspot.com/2008/07/using-helper-to-count-items-in-iterator.html' title='Using a helper to count items in an iterator'/><author><name>Jim Keller</name><uri>http://www.blogger.com/profile/04379106179273487649</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4736082337228328098.post-2687988229891251752</id><published>2008-07-05T13:28:00.001-07:00</published><updated>2008-07-06T22:17:20.937-07:00</updated><title type='text'>Adding to multiple tables from one form</title><content type='html'>Today I had a situation where I needed to add to the customer_addresses table when creating a new entry in the customers table. Fuse made this a simple exercise:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;views/Customer/Customer-Edit.tmpl&lt;/span&gt;&lt;br /&gt;&lt;pre class="view_code"&gt;&lt;br /&gt;&amp;lt;{IF message}&amp;gt;&lt;br /&gt;&amp;lt;div style="margin-bottom: 8px; font-weight: bold; text-align:center; padding: 2px;"&amp;gt;&lt;br /&gt;  &amp;lt;{message}&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;{/IF}&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;{form_script_tag}&amp;gt;&lt;br /&gt;&amp;lt;{form_tag}&amp;gt;&lt;br /&gt;&lt;br /&gt;  &lt;br /&gt;&amp;lt;div style="margin-top: 6px;"&amp;gt;First Name&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div&amp;gt;&amp;lt;{HTML/FormHelper::text_field('Customer', 'customer_f_name') }&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;  &lt;br /&gt;&amp;lt;div style="margin-top: 6px;"&amp;gt;Last Name&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div&amp;gt;&amp;lt;{HTML/FormHelper::text_field('Customer', 'customer_l_name') }&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;  &lt;br /&gt;&amp;lt;div style="margin-top: 6px;"&amp;gt;Email&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div&amp;gt;&amp;lt;{HTML/FormHelper::text_field('Customer', 'customer_email') }&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;  &lt;br /&gt;&amp;lt;div style="margin-top: 6px;"&amp;gt;Address Line 1&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div&amp;gt;&amp;lt;{HTML/FormHelper::text_field('CustomerAddress', 'l1') }&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;  &lt;br /&gt;&amp;lt;div style="margin-top: 6px;"&amp;gt;Address Line 2&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div&amp;gt;&amp;lt;{HTML/FormHelper::text_field('CustomerAddress', 'l2') }&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;  &lt;br /&gt;&amp;lt;div style="margin-top: 6px;"&amp;gt;City&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div&amp;gt;&amp;lt;{HTML/FormHelper::text_field('CustomerAddress', 'city_name') }&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;  &lt;br /&gt;  &lt;br /&gt;&amp;lt;div style="margin-top: 6px;"&amp;gt;State&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div&amp;gt;&amp;lt;{HTML/FormOptionsHelper::Select_all('State', 'name', 'abbr', array('for_model' =&amp;gt; 'CustomerAddress', 'for_field' =&amp;gt; 'state_abbr')) }&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;  &lt;br /&gt;&amp;lt;div style="margin-top: 6px;"&amp;gt;Zip&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div&amp;gt;&amp;lt;{HTML/FormHelper::text_field('CustomerAddress', 'zip_code') }&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;  &lt;br /&gt;&amp;lt;div&amp;gt;&lt;br /&gt;  &amp;lt;input type="submit" value="Save Changes" /&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;  &lt;br /&gt;&amp;lt;/form&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;controllers/CustomerController.class.php&lt;/span&gt;&lt;br /&gt;&lt;pre class="controller_code"&gt;&lt;br /&gt; public function after_add() {&lt;br /&gt;  &lt;br /&gt;  if ( $this-&gt;is_postback() ) {&lt;br /&gt;&lt;br /&gt;   FUSE::Require_model('CustomerAddress');&lt;br /&gt;     &lt;br /&gt;   $address = new CustomerAddress();&lt;br /&gt;   $address-&gt;customer_id = $this-&gt;customer-&gt;id;&lt;br /&gt;   $address-&gt;add_from_form();&lt;br /&gt; &lt;br /&gt;   $this-&gt;redirect( 'customer/view/' . $this-&gt;model-&gt;id );&lt;br /&gt;  }&lt;br /&gt;   &lt;br /&gt; }&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;More information on Fuse can be found at &lt;a href="http://www.phpfuse.net"&gt;http://www.phpfuse.net&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4736082337228328098-2687988229891251752?l=fusephpmvc.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://fusephpmvc.blogspot.com/feeds/2687988229891251752/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4736082337228328098&amp;postID=2687988229891251752' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4736082337228328098/posts/default/2687988229891251752'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4736082337228328098/posts/default/2687988229891251752'/><link rel='alternate' type='text/html' href='http://fusephpmvc.blogspot.com/2008/07/adding-to-multiple-tables-in-from-one.html' title='Adding to multiple tables from one form'/><author><name>Jim Keller</name><uri>http://www.blogger.com/profile/04379106179273487649</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4736082337228328098.post-4202818609850070891</id><published>2008-07-03T10:46:00.001-07:00</published><updated>2008-07-06T22:18:02.611-07:00</updated><title type='text'>Using a view for css so you can use variables in .css files</title><content type='html'>Oftentimes, you are developing in an environment that has a different base uri (e.g. &lt;span style="font-style:italic;"&gt;http://localhost/projects/myproject&lt;/span&gt;) than the final project will have (&lt;span style="font-style:italic;"&gt;http://www.projectdomain.com&lt;/span&gt;). &lt;br /&gt;&lt;br /&gt;This isn't a problem in normal views/templates in FUSE, because you have the SITE_BASE_URI variable available to you. However, regular CSS files aren't parsed by the templating engine, so you have to explicitly specify the url for, say, background images. Let's take a look at how we can use FUSE to get our SITE_BASE_URI and other variables embedded in the css file so they work in any environment. &lt;br /&gt;&lt;br /&gt;Here is our CSS file, &lt;span style="font-weight:bold;"&gt;mystylesheet.css&lt;/span&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;body {&lt;br /&gt;   /* this image only loads if our base uri is / */&lt;br /&gt;   background: url(/images/body_bg.jpg);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The problem is that some developers may be working at a base uri of /projects or /projectname, etc, so linking to / will cause the image not to load. We can get around this in Fuse by creating a controller for CSS files and having them parsed as templates. Here's how:&lt;br /&gt;&lt;br /&gt;&lt;div class="step_heading"&gt;1. Create the controller&lt;/div&gt;&lt;br /&gt;&lt;b&gt;controllers/CSSController.class.php&lt;/b&gt;&lt;pre class="controller_code"&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;FUSE::Require_class('AppControl/FuseApplicationController');&lt;br /&gt;&lt;br /&gt;class CSSController extends FuseApplicationController {&lt;br /&gt;&lt;br /&gt; public $skip_pre_action = true;&lt;br /&gt; public $header_auto_render = false;&lt;br /&gt; public $footer_auto_render = false;&lt;br /&gt;&lt;br /&gt; public $template_directory = 'css';&lt;br /&gt; &lt;br /&gt;    function load() {&lt;br /&gt;     &lt;br /&gt;     if ( $this-&gt;filename ) {&lt;br /&gt;      &lt;br /&gt;      &lt;br /&gt;      $this-&gt;set_template_filename( "{$this-&gt;template_directory}/$this-&gt;filename", array( 'append_extension' =&gt; false ) );&lt;br /&gt;      &lt;br /&gt;      header('Content-Type: text/css');&lt;br /&gt;      $this-&gt;render(); &lt;br /&gt;      &lt;br /&gt;     }&lt;br /&gt;     &lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;In the controller above, we're explicitly setting the template file to be "css/&lt;span style="font-weight:bold;"&gt;$this-&gt;filename&lt;/span&gt;", where &lt;span style="font-weight:bold;"&gt;$this-&gt;filename&lt;/span&gt; will be the .css filename from the route itself, as we'll see below. &lt;br /&gt;&lt;br /&gt;&lt;div class="step_heading"&gt;2. Add the route&lt;/div&gt;&lt;br /&gt;adding our route for css/load/{filename} to &lt;span style="font-weight:bold;"&gt;config/routes.conf.php&lt;/span&gt;:&lt;br /&gt;&lt;pre class="code"&gt;&lt;br /&gt;FuseURIRouter::route_connect( 'css/load/:filename', array( &lt;br /&gt;      'action' =&gt; 'load',&lt;br /&gt;      'controller' =&gt; 'CSS', &lt;br /&gt;      'requirements' =&gt; array( 'filename' =&gt; '/.+/' )&lt;br /&gt;       ,&lt;br /&gt;       'static_cache' =&gt; array( 'always' =&gt; true, 'id' =&gt; 'filename', 'headers' =&gt; 'Content-type: text/css' ),      &lt;br /&gt;     )&lt;br /&gt;       );  &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;div class="step_heading"&gt;3. Move the css file to views/css and add variables&lt;/div&gt;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;views/css/mystylesheet.css&lt;/span&gt;&lt;br /&gt;&lt;pre class="view_code"&gt;&lt;br /&gt;body {&lt;br /&gt;   background: url(&lt;{SITE_BASE_URI}&gt;/images/body_bg.jpg);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;div class="step_heading"&gt;4. Link the CSS file in the header&lt;/div&gt;&lt;br /&gt;We created our route for loading CSS templates as css/load/{cssfilename}, so let's now link our new css template in the header:&lt;br /&gt;&lt;br /&gt;adding to &lt;span style="font-weight:bold;"&gt;views/Layout/default/default-header.tmpl&lt;/span&gt;:&lt;br /&gt;&lt;pre class="view_code"&gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;!-- Other head elements --&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;link rel="stylesheet" type="text/css" media="all" href="&lt;{SITE_BASE_URI}&gt;/css/load/mystylesheet.css" /&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;And there you have it. You may notice that in the route the we are statically caching the css file. This is because it takes server overhead to load Fuse for each CSS file, but if we statically cache the file (which saves it as a regular css file), Fuse doesn't have to load, so our overhead is kept to a minimum. You can read more about Fuse's static cache at &lt;a href="http://phpfuse.net/wiki/index.php?title=Static_Page_Caching"&gt;http://phpfuse.net/wiki/index.php?title=Static_Page_Caching&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;More information on the &lt;a href="http://www.phpfuse.net"&gt;Fuse MVC Framework for PHP&lt;/a&gt; can be found at &lt;a href="http://www.phpfuse.net"&gt;http://www.phpfuse.net&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4736082337228328098-4202818609850070891?l=fusephpmvc.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://fusephpmvc.blogspot.com/feeds/4202818609850070891/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4736082337228328098&amp;postID=4202818609850070891' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4736082337228328098/posts/default/4202818609850070891'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4736082337228328098/posts/default/4202818609850070891'/><link rel='alternate' type='text/html' href='http://fusephpmvc.blogspot.com/2008/07/using-view-for-css-so-you-can-use.html' title='Using a view for css so you can use variables in .css files'/><author><name>Jim Keller</name><uri>http://www.blogger.com/profile/04379106179273487649</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry></feed>
