Wednesday, May 19, 2010

YUI Tips

1. YUI Container
http://developer.yahoo.com/yui/container/

Seven Examples of YUI Panels
http://icant.co.uk/sandbox/yuipanel/

2. YUI Event
http://developer.yahoo.com/yui/event/

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);
       }
    }
}

treePanel.show();
YAHOO.util.Event.addListener(document, 'mousedown', onDocumentMouseDown, null);


4. YUI namespace
http://www.yuiblog.com/blog/2007/06/12/module-pattern/

YAHOO.namespace("mySwitch");
YAHOO.mySwitch.panelTable = new YAHOO.widget.Panel("panelTable");

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 () {
} ();

Javascript Syntax

Javascript Tutorial
http://www.tizag.com/javascriptT/javascriptsyntax.php

document.write("something something");

window.location = "http://...";

function prompter() {
   var reply = prompt("what's your name?", "");
   alert("Nice to see you " +reply+"!");
}

window.print();

function delayer() {
   window.location="../xxxx.php";
}

body onload="setTimeout('delayer()', 5000)"

window.open("http://...", "name of window", "status =1, height=300, width=300, resizable = 0");

if(elem.value.length ==0) {
   elem.focus();
}

var numericExpression = /^[0-9[+$/;
if(elem.value.match(numericExpression)) {
}

javascript void 0
News Flash
because alert() returns null value


Set myNum Please


indexof
var aURL = "http://www.tizag.com/";
var aPosition = aURL.indexOf("www");
document.write("The position of www = " + aPosition);


Javascript Tutorial 2
http://home.cogeco.ca/~ve3ll/jstutor0.htm

Good Resource
JavaFile.com
http://www.javafile.com/

JavaScript.net
http://www.java-scripts.net/

Thursday, May 13, 2010

OOP with PHP 5.x

OOP
http://www.scribd.com/doc/38423/Object-Oriented-Programming-in-PHP-5
  • Abstraction
  • Modularization
  • Ecapsulation
  • Extensibility
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;
   }

}

Understanding PHP Object Model
http://www.slideshare.net/sebastian_bergmann/understanding-the-php-object-model




CSS Techniques

1. CSS Drop Shadows
http://www.alistapart.com/articles/cssdropshadows/



2. Rounded Corner
http://spiffybox.com/



3. Free Graphics and Effects
http://journalxtra.com/2009/08/snazz-up-your-website-with-free-graphics-and-sound-effects/

Symfony: debugging (1.4)

1. Unwanted " in action

# ProjectName/apps/appsName/config/settings.yml
# Output escaping settings
    #escaping_strategy: true
    #escaping_method: ESC_SPECIALCHARS


2. Call to undefined method dashboardActions::returnJsonResponse
# ProjectName/lib/symfony/Actions.class.php

class Actions extends sfActions {

}









Monday, May 10, 2010

Symfony 1.4: Create New Project

1. Create project directory under ~/workspace/
[root/workspace]# mkdir ProjectName

2. Create project
[root/workspace/ProjectName]# symfony14 generate:project ProjectName

in Eclipse
File > New > PHP Project
Project name: ProjectName

3. Create application
[root/workspace/ProjectName]# symfony14 generate:app appName

4. Configuration
[root/workspace/ProjectName]# chmod 777 cache/ log/

create symfony softlink
[root/workspace/ProjectName/web]# ln -s /opt/symfony/symfony14/data/web/sf

create softlink
[root]# cd /var/www/html
[root/var/www/html]# ln -s ~/workspace/ProjectName

under workspace/phplib
[root/workspace/phplib]# ln -s ~/workspace/PHPLIB_***Adapter/***Service ***Service

5. Create module
under project directory ProjectName
[root/workspace/ProjectName]# symfony14 generate:module appsName newModuleName

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()

11. Auth
Load AuthenticationService

# ProjectName/config/ProjectConfiguration.class.php
require_once('AuthenticationService/service/ASA_AuthSession.php');

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.');
}

configure factories.yml

# ProjectName/apps/appName/config/factories.yml
all:
   user:
    class: Auth


12. Login
Create new component instance in CSC

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

Friday, May 7, 2010

Symfony: Multiple Version in same environment

Your Complete Guide to Running Multiple
Symfony Versions on the Same Environment
http://symfonynerds.com/blog/?p=123

Step 1 Uninstall any existing symfony installations
[root]# pear uninstall symfony/symfony
uninstall ok: channel://pear.symfony-project.com/symfony-1.0.20

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
ln -s /opt/symfony/symfony10/data/bin/symfony /usr/bin/symfony10
ln -s /opt/symfony/symfony11/data/bin/symfony /usr/bin/symfony11
ln -s /opt/symfony/symfony12/data/bin/symfony /usr/bin/symfony12
ln -s /opt/symfony/symfony12/data/bin/symfony /usr/bin/symfony13
ln -s /opt/symfony/symfony12/data/bin/symfony /usr/bin/symfony14

To test the links
[root]# symfony10 -V
symfony versoin 1.0.22-LAST
[root]# symfony11 -V
symfony versoin 1.1.10-DEV (/opt/symfony/symfony11/lib)

Step 5 Update any existing symfony 1.0 projects to use the following include directories
project/config/config.php
$sf_symfony_lib_dir  = '/opt/symfony/symfony10/lib';
$sf_symfony_data_dir = '/opt/symfony/symfony10/data';


Step 6 New symfony 1.4 projects can use the following to create the projects
symfony14 generate:project ProjectName