12/11/2011 3:50pm

PHP | Problem - Collection of code

<% if Menu(2) %>

<ul id="Menu2">
<% control Menu(2) %>
<li class="$LinkingMode"><a href="$Link" title="Go to the &quot;{$Title}&quot; page">$MenuTitle</a></li>
<% end_control %>
<% end_if %>

Basic Logoc:
and :
<%if foo && bar %>
or :
<%if foo || bar %>
<% if foo %>
<% else_if bar %>
<% else %>

$Content.LimitCharacters ( [$limit = 20], [$add = "..."] )
_ controller extend Page_controller << controller is ONLY processes when that page type is visited. when DataObject is ready in the DB for access from anywhere.
They are 2 different types of template. ArticleHolder.ss maps to a class ArticleHolder but the search template maps to a function on Page - function action() on a ArticleHolder().

So if you have a function date() on your ArticleHolder class, and a url like site.com/articles/date then it'll use ArticleHolder_date.ss.

See the template documentation for more information.

<% base_tage %>
<% if Level(2) %>
<% end_if %>

<% if Menu(2) %>
<% control Menu(2) %>
<% end_control %>
<% end_if %>

CSS Files
By standard SilverStripe uses 3 CSS Files for your site -
• layout.css contains the layout and design of the site
• typography.css contains the styling for the text/fonts/links (used in both front and back ends)
• form.css styling for forms. Overriding
The templating system will search for the appropriate files in the following order:
1. mysite (or other name given to site folder)
2. themes
3. module (eg blog)
If you have a theme called mytheme_forum, it is considered to be a 'subtheme' of the mytheme theme. This lets module developers release extensions to popular themes that will let their module work with that theme.
A subtheme overrides the files in the module. So for instance, if you have the forum setup instead of editing the files within the forum/ module you would create a themes/yourtheme_forum/ folder.


If you want to refer to an image or other file asset in a .ss template, use $ThemeDir. For example:
<img src="$ThemeDir/images/log.gif" />

If your image is in a subtheme, you can refer to that with an argument to ThemeDir. For example, if your image was in mytheme_forum, you could use the following code:
<img src="$ThemeDir(forum)/images/log.gif" />

Including Javascript & CSS
Including inside PHP Code

Including inside Template files
<% require css(cms/css/TreeSelector.css) %>
<% require themedCSS(TreeSelector) %>
<% require javascript(cms/javascript/LeftAndMain.js) %>
Note that currently (as of 2.3) you cannot pass a second parameter to a function via the template parser so doing the following will not work.
<% require css(cms/css/TreeSelector.css, 'screen,projection') %>
Combining Files
You can concatenate several CSS or javascript files into a single dynamically generated file. This increases performance reducing HTTP requests. Note that for debugging purposes combined files is disabled in devmode.
8 // supports CSS + JS
By default it stores the generated file in the assets/ folder but you can configure this by setting
2 // relative from the base folder
If SilverStripe doesn't have permissions on your server to write these files it will default back to including them individually .


Quick Reference
Below is a list of fields and methods that are typically available for templates (grouped by their source) - use this as a quick reference (not all of them are described above):
All methods available in Page_Controller
$NexPageLink, $Link, $RelativeLink, $ChildrenOf, $Page, $Level, $Menu, $Section2, $LoginForm, $SilverStripeNavigator, $PageComments, $Now, $LinkTo, $AbsoluteLink, $CurrentMember, $PastVisitor, $PastMember, $XML_val, $RAW_val, $SQL_val, $JS_val, $ATT_val, $First, $Last, $FirstLast, $MiddleString, $Middle, $Even, $Odd, $EvenOdd, $Pos, $TotalItems, $BaseHref, $Debug, $CurrentPage, $Top
All fields available in Page_Controller
$ID, $ClassName, $Created, $LastEdited, $URLSegment, $Title, $MenuTitle, $Content, $MetaTitle, $MetaDescription, $MetaKeywords, $ShowInMenus, $ShowInSearch, $HomepageForDomain, $ProvideComments, $Sort, $LegacyURL, $HasBrokenFile, $HasBrokenLink, $Status, $ReportClass, $ParentID, $Version, $EmailTo, $EmailOnSubmit, $SubmitButtonText, $OnCompleteMessage, $Subscribe, $AllNewsletters, $Subject, $ErrorCode, $LinkedPageID, $RedirectionType, $ExternalURL, $LinkToID, $VersionID, $CopyContentFromID, $RecordClassName
All methods available in Page
$Link, $LinkOrCurrent, $LinkOrSection, $LinkingMode, $ElementName, $InSection, $Comments, $Breadcrumbs, $NestedTitle, $MetaTags, $ContentSource, $MultipleParents, $TreeTitle, $CMSTreeClasses, $Now, $LinkTo, $AbsoluteLink, $CurrentMember, $PastVisitor, $PastMember, $XML_val, $RAW_val, $SQL_val, $JS_val, $ATT_val, $First, $Last, $FirstLast, $MiddleString, $Middle, $Even, $Odd, $EvenOdd, $Pos, $TotalItems, $BaseHref, $CurrentPage, $Top
All fields available in Page
$ID, $ClassName, $Created, $LastEdited, $URLSegment, $Title, $MenuTitle, $Content, $MetaTitle, $MetaDescription, $MetaKeywords, $ShowInMenus, $ShowInSearch, $HomepageForDomain, $ProvideComments, $Sort, $LegacyURL, $HasBrokenFile, $HasBrokenLink, $Status, $ReportClass, $ParentID, $Version, $EmailTo, $EmailOnSubmit, $SubmitButtonText, $OnCompleteMessage, $Subscribe, $AllNewsletters, $Subject, $ErrorCode, $LinkedPageID, $RedirectionType, $ExternalURL, $LinkToID, $VersionID, $CopyContentFromID, $RecordClassName

Represents an image object, inheriting all base functionality from the file class with extra functionality including resizing.
Resizing Images in PHP
The following are methods defined on the GD class which you can call on Image Objects. Note to get the following to work you need to have GD2 support in your PHP installation and // manipulation functions
$image->resize(width,height); // Basic resize, just skews the image
$image->resizeRatio(width,height) // Resizes an image with max width and height
$image->paddedResize(width,height) // Adds padding after resizing to width or height.
$image->croppedResize(width,height) // Crops the image from the centre, to given values.
$image->resizeByHeight(height) // Maximum height the image resizes to, keeps proportion
$image->resizeByWidth(width) // Maximum width the image resizes to, keeps proportion
$image->greyscale(r,g,b) // alters image channels ===
// values
$image->getHeight() // Returns the height of the image.
$image->getWidth() // Returns the width of the image
$image->getOrientation() // Returns a class constant: ORIENTATION_SQUARE or ORIENTATION_PORTRAIT or ORIENTATION_LANDSCAPE

Resizing in Templates
You can call certain resize functions directly from the template, to use the inbuilt GD functions as the template parser supports these, for example SetWidth() or SetHeight().
For output of an image tag with the image automatically resized to 80px width, you can use:
$Image.SetWidth(80) // returns a image 80px wide, ratio kept the same
$Image.SetHeight(80) // returns a image 80px tall, ration kept the same
$Image.SetSize(80,80) // returns a 80x80px padded image
$Image.SetRatioSize(80,80) // **New in 2.4** returns an image scaled proportional, with its greatest diameter scaled to 80px
$Image.PaddedImage(80, 80) // Returns an 80x80 image. Unused space is padded white. No crop. No stretching
$Image.Width // returns width of image
$Image.Height // returns height of image
$Image.Orientation // returns Orientation
$Image.Filename // returns filename
$Image.URL // returns filename
$CroppedImage(600,400) (with DOM)
$CroppedImage(600,400).URL // URL !!!

Data Types
These are the data-types that you can use when defining your data objects. They are all subclasses of DBField for introducing their usage.
• Varchar: A variable-length string of up to 255 characters, designed to store raw text
• Text: A variable-length string of up to 2 megabytes, designed to store raw text
• HTMLVarchar: A variable-length string of up to 255 characters, designed to store HTML
• HTMLText: A variable-length string of up to 2 megabytes, designed to store HTML
• Enum: An enumeration of a set of strings
• Boolean: A boolean field.
• Int: An integer field.
• Decimal: A decimal number.
• Currency: A number with 2 decimal points of precision, designed to store currency values.
• Percentage: A decimal number between 0 and 1 that represents a percentage.
• Date: A date field
• SS_Datetime: A date / time field
• Time: A time field

Form Field Types ¶
• SimpleHTMLEditorField // DOM Related + Give basic Editor UI
• AjaxUniqueTextField: Text field that automatically checks that the value entered is unique for the given set of fields in a given set of tables
• AutocompleteTextField
• ConfirmedPasswordField: Shows two password-fields, and checks for matching passwords.
• CreditCardField
• CurrencyField
• EmailField
• HTMLEditorField: A WYSIWYG editor field, powered by tinymce.
• NumericField: A Single Numeric field extending a typical TextField but with validation.
• PasswordField
• UniqueRestrictedTextField: Text field that automatically checks that the value entered is unique for the given set of fields in a given set of tables
• UniqueTextField: Text field that automatically checks that the value entered is unique for the given set of fields in a given set of tables
• DateField: Represents a date in a textfield (New Zealand)
• DatetimeField: Combined date- and time field
• TimeField: Represents time in a textfield (New Zealand)

• CompositeField: Base class for all fields that contain other fields. Uses <div> in template, but doesn't necessarily have any visible styling.
• FieldGroup: Same as CompositeField, but has default styling (indentation) attached in CMS-context.
• FieldSet: Basic container for sequential fields, or nested fields through CompositeField. Does NOT render a <fieldgroup>.
• TabSet
• Tab
• Form for more info
• InlineFormAction: Render a button that will act as If you want to add custom behaviour, please set {inlcudeDefaultJS} to false and work with behaviour.js.
• Image: Action that uses an image instead of a button
• InlineFormAction: Prevents placement of a button in the CMS-button-bar.
• FileField: Simple file upload dialog.
• FileIFrameField: File uploads through an iframe
• ImageField: Image upload through an iframe, with thumbnails and file-selection from existing assets
• SimpleImageField: SimpleImageField provides an easy way of uploading images to Image has_one relationships. Unlike ImageField, it doesn't use an iframe.

new TextareaField(
$name = "description",
$title = "Description",
$rows = 8,
$cols = 3,
$value = "This is the default description"

• ComplexTableField: Provides a tabuar list in your form with view/edit/add/delete links to modify records with a "has-one"-relationship (in a lightbox-popup).
• HasManyComplexTableField
• HasOneComplexTableField
• LanguageDropdownField: An extension to dropdown field, pre-configured to list languages. Tied into i18n.
• ManyManyComplexTableField
• TableField
• TableListField
• TreeDropdownField
• TreeMultiselectField: represents many-many joins using a tree selector shown in a dropdown-like element
• WidgetArea
• DatalessField - Base class for fields which add some HTML to the form but don't submit any data or save it to the database
• HeaderField: Renders a simple <h1>-<h6> header
• HiddenField
• LabelField
• LiteralField: Renders arbitrary HTML into a form.
CMS Field Editor
Please see HTMLEditorField for in-depth documentation about custom forms created through a GUI in the CMS.

if(strpos($_SERVER['REQUEST_URI'], '/blog') === 0) SSViewer::set_theme('blog');

PHP <<<<<<<<<<<<<<<<<<<<<<<<<<<<PHP
Members & Administration

function init(){ parent::init(); if(member_logged_in){setThemeHere;}}

Set a page type settings from PHP , Set Default config !
static $defaults = array(
"ShowInMenus" => 0,
"ShowInSearch" => 0