Use YAHOO.lang.extend
superclass is part of the inheritance mechanism provided by YUI’s extend method. After you declare the constructor for your new object, you call extend:
YAHOO.lang.extend(YAHOO.SATYAM.LoadingPanel, YAHOO.widget.Panel);
The constructor itself does not get executed immediately. The extend function does get executed immediately.
We use method call of JavaScript native Function object, which takes the first argument as the execution scope of the function called and passes it the rest of the arguments.
To Use the object we just created
if (!loadingPanel2) {
loadingPanel2 = new YAHOO.SATYAM.LoadingPanel();
}
loadingPanel2.show();
Puts all the code within an anonymous function, which gets immediately executed (notice the empty parenthesis at the end)
YAHOO.namespace('SATYAM');
(function(){
var Dom = YAHOO.util.Dom,
Event = YAHOO.util.Event, Panel = YAHOO.widget.Panel;
// here goes the library contents itself
// constructor
// extend component
})();
YAHOO.register('SATYAM.LoadingPanel', YAHOO.SATYAM.LoadingPanel, {version: "0.99", build: '11'});
After we declare the instance of the YUI Loader that we will use, we call method addModule providing the information about our library file
var loader = new YAHOO.util.YUILoader();
YUI 2: Drag & Drop http://developer.yahoo.com/yui/dragdrop/
var dd1 = new YAHOO.util.DD("element1");
var dd2 = new YAHOO.util.DDProxy("element2"); //proxy element during movement
var dd3 = new YAHOO.util.DDTarget("element3"); //target for drag & drop interaction
Drag & Drop Manager
YAHOO.util.DragDropMgr (or alias YAHOO.util.DDM)
//sets the time delay between a mousedown and a
//drag event to 1200 milliseconds:
YAHOO.util.DragDropMgr.clickTimeThresh = 1200;
Interaction Groups
Each Drag and Drop object belongs to one or more interaction groups. Drag and Drop events fire only when the dragged element interacts with other objects that with which it shares a group membership. If no group is specified in the constructor, an object belongs to the "default" group
// No group specified so dd0 is assigned to the "default" group
var dd0 = new YAHOO.util.DD("elementid0");
// dd1 is a member of group1
var dd1 = new YAHOO.util.DD("elementid1", "group1");
// dd2 is a member of group2
var dd2 = new YAHOO.util.DD("elementid2", "group2");
// dd3 is a member of both group1 and group2
var dd3 = new YAHOO.util.DD("elementid3", "group1");
dd3.addToGroup("group2");
//groups can be removed via script as well:
dd1.removeFromGroup("group1");
Interesting Moments & Custom Events
var dd = new YAHOO.util.DD('demo');
dd.on('dragEvent', function(ev) {
YAHOO.log('Element is being dragged.');
}, dd, true);
assign a variable to an unnamed function: consider the function as an object
var add = function(a, b)
{
return a+b;
}
var add=function theAdd(a, b)
{
return a+b;
}
alert(add(1,2)); // produces 3
alert(theAdd(1,2)); // also produces 3
Useful in object oriented program, we can have a function be a property of an object
var myObject=new Object();
myObject.add=function(a,b){return a+b};
// myObject now has a property/a method named "add"
// and I can use it like below
myObject.add(1, 2);
When we declare a function, JavaScript actually creates an object;
We can add properties to Objects, including function objects.
function Ball() // it may seem odd, but declaration
{ // creates an object named Ball, and you can
} // refer to it or add properties to it like below
Ball.callsign="The Ball"; // add property to Ball
alert(Ball.callsign); // produces "The Ball"
Since function is an object, we can assign a pointer to a function
function myFunction(message)
{
alert(message);
}
var ptr=myFunction; // ptr points to myFunction
ptr("hello"); // executes myFunction which will prints "hello"
By declaring a function, we have also created a new data type
function Ball(message)
{
alert(message);
} var ball0=new Ball("creating new Ball"); // creates object &
// prints the message
ball0.name="ball-0"; // ball0 now has a "name" property
alert(ball0.name); // prints "ball-0"
The red portion as a shortcut for doing below
function Ball(message)
{
alert(message);
} var ball0=new Object(); ball0.construct=Ball; ball0.construct("creating new ball"); // executes ball0.Ball("creating..");
ball0.name="ball-0";
alert(ball0.name);
Constructor function
function Ball(message, specifiedName)
{
alert(message);
this.name=specifiedName;
}
var ball0=new Ball("creating new Ball", "Soccer Ball");
alert(ball0.name); // prints "Soccer Ball"
The "new" keyword eventually causes the constructor function to be executed. In this case, it will executel Ball("creating new Ball", "Soccer Ball"); and the
keyword this will refer to ball0.
Therefore, the line: this.name=specifiedName becomes ball0.name="Soccer Ball".
Every constructor function has a property named prototype.
You do not need to explicitly declare a prototype property, because it exists on every constructor function.
function Test()
{
}
alert(Test.prototype); // prints "Object"
Prototype is an object
when an object is created, the constructor function assigns its prototype property to the internal __proto__ property of the new object.
function Fish(name, color)
{
this.name=name;
this.color=color;
}
Fish.prototype.livesIn="water";
Fish.prototype.price=20;
You can use prototype to assign functions that are common on all objects
function Employee(name, salary)
{
this.name=name;
this.salary=salary;
}
Employee.prototype.getSalary=function getSalaryFunction()
{
return this.salary;
}
Employee.prototype.addSalary=function addSalaryFunction(addition)
{
this.salary=this.salary+addition;
}
$t = new lime_test(1);
$t->pass('This test always passes.');
To launch the test $ php test/unit/test.php
Sample
require_once dirname(__FILE__).'/../bootstrap/unit.php';
$t = new lime_test(6); // display 1..6
$t->comment('::slugify()'); // display #::slugify()
$t->is(Jobeet::slugify('Sensio'), 'sensio', '::slugify() converts all characters to lower case'); // display ok 1 - ::slugify() converts all ...
3. User Flash (symfony 1.4) http://www.symfony-project.org/jobeet/1_4/Doctrine/en/13
A flash is an ephemeral message stored in the user session that will be automatically deleted after the very next request. It is very useful when you need to display a message to the user after a redirect.
setFlash(): The first argument is the identifier of the flash and the second one is the message to display. You can define whatever flashes you want, but notice and error are two of the more common ones.
// apps/frontend/modules/job/actions/actions.class.php
public function executeExtend(sfWebRequest $request)
{
$request->checkCSRFProtection();
$this->getUser()->setFlash('notice', sprintf('Your job validity has been extended until %s.', $job->getDateTimeObject('expires_at')->format('m/d/Y')));
4. User Attribute (symfony 1.4) http://www.symfony-project.org/jobeet/1_4/Doctrine/en/13 getAttribute(), setAttribute()
// apps/frontend/modules/job/actions/actions.class.php
class jobActions extends sfActions
{
public function executeShow(sfWebRequest $request)
{
$this->job = $this->getRoute()->getObject();
// fetch jobs already stored in the job history
$jobs = $this->getUser()->getAttribute('job_history', array());
// add the current job at the beginning of the array
array_unshift($jobs, $this->job->getId());
// store the new job history back into the session
$this->getUser()->setAttribute('job_history', $jobs);
}
} myUser class
The myUser class overrides the default symfony base sfUser class with application specific behaviors
// apps/frontend/modules/job/actions/actions.class.php
class jobActions extends sfActions
{ public function executeShow(sfWebRequest $request) { $this->job = $this->getRoute()->getObject();
$this->getUser()->addJobToHistory($this->job); }
}
// apps/frontend/lib/myUser.class.php
class myUser extends sfBasicSecurityUser
{ public function addJobToHistory(JobeetJob $job) { $ids = $this->getAttribute('job_history', array());
if (!in_array($job->getId(), $ids)) { array_unshift($ids, $job->getId()); $this->setAttribute('job_history', array_slice($ids, 0, 3)); }
}
} remove attribute
User's attributes are managed by an object of class sfParameterHolder. The getAttribute() and setAttribute() methods are proxy methods for getParameterHolder()->get() and getParameterHolder()->set().
// apps/frontend/lib/myUser.class.php
class myUser extends sfBasicSecurityUser
{ public function resetJobHistory() { $this->getAttributeHolder()->remove('job_history'); }
}
5. i18n and l10n (symfony 1.4) http://www.symfony-project.org/jobeet/1_4/Doctrine/en/19 User Culture
The language French is ‘fr’, English is ‘en’; the country Canada is ‘CA’, United States is ‘US’; the culture for a user speaking French from Canada is ‘fr_CA’
setCulture()and getCulture()
// in an action
$this->getUser()->setCulture('fr_BE');
echo $this->getUser()->getCulture();
The preferred user culture can be configured in the settings.yml configuration file
#apps/frontend/config/settings.yml
all:
.settings:
default_culture: en_CA
Internationalization
set i18n setting to true in settings.yml
# apps/frontend/config/settings.yml
all:
.settings:
charset: utf-8
i18n: true
The I18N helper group is not loaded by default, you need to either manually add itin each template with use_helper(‘I18N’) or load it globally by adding to the standard_helpers setting
# apps/frontend/config/settings.yml
all:
.settings:
standard_helpers: [Partial, Cache, I18N]
Each translation is managed by a trans-unit tag which has a unique id attribute. A lot of tools exist to ease the translation process. (check out Open Language Tools https://open-language-tools.dev.java.net/)
7. Authentication (symfony 1.4)
entire application require the user to be authenticated
# apps/backend/config/security.yml
default:
is_secure: true
when an un-authenticated user tries to access a secured action, symfony forwards the request to the login action
# apps/backend/config/setting.yml
all: .actions:
login_module: default
login_action: login
By default, the myUser class extends sfBasicSecurityUser, and not sfUser. sfBasicSecurityUser provides additional methods to manage user authentication and authorization.
To manage user authentication, use the isAuthenticated() and setAuthenticated() methods:
if (!$this->getUser()->isAuthenticated())
{
$this->getUser()->setAuthenticated(true);
}
9. Use Helper in Action http://snippets.symfony-project.org/snippet/69
In PrjectConfiguration file
# ProjectName/config/ProjectConfiguration.class.php
include_once('/opt/symfony/symfony14/lib/helper/DateHelper.php');
YAHOO.util.Event.addListener(el, sType, fn, obj, overrideContext) el: id, or a collection of ids sType: the type of event to append (such as "click" http://www.quirksmode.org/dom/events/) fn: the method the event invokes obj: an arbitrary object that will be passed as a parameter to the handler overrideContect: if true, the obj passed in becomes the execution context of the listener; if an object, this object becomes the execution context
YAHOO.util.Subscriber( fn , obj , overrideContext ) fn: the function to execute obj: an object to be passed along when the event fires overrideContext: If true, the obj passed in becomes the execution context of the listener
There are 2 main types of event subscriptions:
//DragDrop
var dd = new YAHOO.util.DD('dd');
dd.on('dragEvent', function() { });
//Panel
var panel = new YAHOO.widget.Panel('panel');
panel.renderEvent.subscribe(function() {});
//Calendar
var cal = new YAHOO.widget.Calendar('cal');
cal.selectEvent.subscribe(function() {});
//Editor
var editor = new YAHOO.widget.Editor('editor', {});
editor.on('afterRender', function() {});
3. Define anonymous function
Defining an anonymous function in order to keep all variables out of the global scope. Inside the anonymous function, define some shortcuts to utils that will be used frequently (Dom and Event).
(function () {
var Event = YAHOO.util.Event,
Dom = YAHOO.util.Dom;
}());
Inside the the anonymous function, use the onDOMReady method of the Event utility to instantiate an Overlay and a Button when the page's DOM is ready to be scripted.
Event.onDOMReady(function () {
var oCalendarMenu;
// Create an Overlay instance to house the Calendar instance
oCalendarMenu = new YAHOO.widget.Overlay("calendarmenu", { visible: false });
// Create a Button instance of type "menu"
var oButton = new YAHOO.widget.Button({
type: "menu", id: "calendarpicker", label: "Choose A Date", menu: oCalendarMenu, container: "datefields" });
});
3. YUI Panel
Click outside of a panel to close it var treePanel = new YAHOO.widget.Panel(...);
function isInsideTreePanel(clicked_element) {
var current_element = clicked_element;
while(current_element && current_element != document.body) {
if (current_element == treePanel.element) {
return true;
}
current_element = current_element.parentNode;
}
return false;
}
function onDocumentMouseDown(e) {
if (treePanel.cfg.getProperty('visible')) {
if (!isInsideTreePanel(e.target)) {
treePanel.hide();
YAHOO.util.Event.removeListener(document, onDocumentMouseDown);
}
}
}
Error: missing ; before statement
if trying to create a public method with “var” keyword YAHOO.namespace("mySwitch"); var YAHOO.mySwitch.panelTable = new YAHOO.widget.Panel("panelTable");
parentheses () at the end of function: cause anonymous function to execute immediately
YAHOO.myProject.myModule = function () {
} ();
Basic
class MyClass {
public $data;
private $private;
static $static = 1;
const constant = 'value';
public function __construct() {
}
public function __destruct() {
}
protected function Action() {
}
private function Action() {
}
public function show() {
}
}
Extending Class class MyClass { public $data; public function __construct() { $this->data = 'Hello World";
}
}
class Second extends MyClass { private $some; public function __construct() { $this->some = 'Second!'; parent::__construct();
} }
Interface & implements
keyword implements:
create class based on interface;
can be combined with extends
interface Template {
public function foo($var);
} class MyClass implements Template { public function foo($var) { echo $var;
} } class MyClass extends foobar implements Template { public function foo($var) { echo $var;
}
6. Set routing
/projectName/apps/appName/config/routing.yml homepage:
url: /
param: { module: public, action: index }
7. Set view
/projectName/apps/appName/config/view.yml
default:
http_metas:
content-type: text/html
metas:
title: Project Name robots: index, follow description: Project Description keywords: xxxx, xxxxx language: en
stylesheets: [main]
javascripts: []
has_layout: on
layout: layout
customize the view for module
# apps/frontend/modules/job/config/view.yml
default:
stylesheets: [public.css]
resetSuccess:
stylesheets: [main.css]
8. Turn on/off debug toolbar
Web Debug Toolbar Activation, in myapp/config/settings.yml
dev:
.settings:
web_debug: true
9. frontend_dev.php IP address check
/projectName/web/frontend_dev.php
// this check prevents access to debug front controllers that are deployed by accident to production servers.
// feel free to remove this, extend it or make something more sophisticated.
if (!in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1')))
{
die('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
Error in Linux, but not on other machine
Warning: session_start() [function.session-start]: Function spl_autoload_call() hasn't defined the class it was called for in /opt/symfony/symfony14/lib/storage/sfSessionStorage.class.php on line 93
Catchable fatal error: Object of class __PHP_Incomplete_Class could not be converted to string in /opt/symfony/symfony14/lib/yaml/sfYamlInline.php on line 105
Tried symfony14 cc, still have the error
Tried symfony14 clear-cache, red box - Task "clear-cache" is not defined
Closed browser without saving, worked (should just clear session/cookie);
symfony clear-cache is changed to symfony cache:clear
10. Forms
1) FormHelper was removed from symfony 1.4, so input_tag(), checkbox_tag() and etc not working.
http://www.symfony-project.org/forms/1_4/en/
2) Notice: Undefined variable: sf_flash
Use $sf_user->hasFlash()
Add Auth.class.php
# ProjectName/lib/symfony/Auth.class.php
public function initialize(sfEventDispatcher $dispatcher, sfStorage $storage, $options = array()) { }
public function setAuthenticated($authenticated) {
#throw new Exception('here');
#sfContext::getLogger()->log('CSC_User::setAuthenticated is not implemented.');
}
public function addCredential($credential) {
#sfContext::getLogger()->log('CSC_User::addCredential is not implemented.');
}
13. After move project / import other's project
Warning: copy(/home/eshare/projects/sfproject2/cache/frontend/prod/config/config_config_handlers.yml.php) [function.copy]: failed to open stream: [B]Permission denied in /home/eshare/projects/sfproject2/lib/vendor/symfony/lib/config/sfConfigCache.class.php on line 359[/B]
Warning: chmod() [function.chmod]: No such file or directory in /home/eshare/projects/sfproject2/lib/vendor/symfony/lib/config/sfConfigCache.class.php on line 365
Warning: require(/home/eshare/projects/sfproject2/cache/frontend/prod/config/config_config_handlers.yml.php) [function.require]: failed to open stream: No such file or directory in /home/eshare/projects/sfproject2/lib/vendor/symfony/lib/config/sfConfigCache.class.php on line 279
Fatal error: require() [function.require]: Failed opening required '/home/eshare/projects/sfproject2/cache/frontend/prod/config/config_config_handlers.yml.php' (include_path='.:/usr/share/php:/usr/share/pear') in /home/eshare/projects/sfproject2/lib/vendor/symfony/lib/config/sfConfigCache.class.php on line 279
clear the cache completely. (remove the folders inside cache)
Also run symfony project:permissions
Step 2 Create a /opt/symfony directory
Install symfony in /usr/share/php/symfony
[root]# cd /opt/ [root/opt]# mkdir symfony
Step 3 Within the created /opt/symfony directory checkout the symfony 1.0 through 1.4 versions using SVN
[root/opt]#cd symfony/ [root/opt/symfony]# svn co http://svn.symfony-project.com/branches/1.0 symfony10
...
[root/opt/symfony]#svn co http://svn.symfony-project.com/branches/1.1 symfony11
... [root/opt/symfony]#svn co http://svn.symfony-project.com/branches/1.2 symfony12
...
[root/opt/symfony]#svn co http://svn.symfony-project.com/branches/1.3 symfony13
... [root/opt/symfony]#svn co http://svn.symfony-project.com/branches/1.4 symfony14
...
Step 4 Create symbolic links to the symfony commands in the bin directory