Development Changes - May 2011

May 24thURL->set() implemented

When you execute $api->getDestinationURL() it returns an object. This object converts itself into URL in string context. You can execute few methods, to interact with that URL such as useAbsoluteURL(). Now you can also use set() to add more parameters

Result

/whatsnew?foo=bar%3F
 

Code

$url=$page->api->getDestinationURL('..')->set('foo','bar?');
$page->add('Text')->set($url);

May 26thImplemented argument passing to init()

Normally all the dependencies object is receiving through $this->api. It's generally a bad practice in Agile Toolkit to take any input inside init() method. Instead chaining should be used and logic should be stored in render(). However if you think that you still need to pass something into init() method, now there is a way.

Pass array as a second argument to add() function and it will be available through $this->di_config;

Result

test123
 

Code

class MyDI extends Text {
    function 
init(){
        
parent::init();
        
$this->set($this->di_config['text']);
    }
}

$page->add('MyDI',array('text'=>'test123'));

May 24thAdded ButtonSet

$bs=$page->add('ButtonSet');
$bs->add('Button')->set('<b>B</b>');
$bs->add('Button')->set('<i>I</i>');
$bs->add('Button')->set('<u>U</u>');

May 20thAdd ability to setup default pathfinder locations

Pathfinder class needs to be loaded very early in your application. By the time init() is executed, it's already been initialized and ready to load your classes. How do push some paths before default ones are in effect? Now you can re-define $api->addDefaultLocations($pathfinder);

In following example, directory "myplugin" located in the base directory of your application can contain "includes", "javascript" and "tpl" folders. Resources in those folders will take precedence over any other location

function addDefaultLocations($pathfinder,$base_dir){
    
$pathfinder->addLocation('myplugin',array(
        
'php'=>'includes',
        
'js'=>'javascript',
        
'template'=>'tpl',
      ))
      ->
setBasePath($base_dir);
}

May 18thFix UI-test

Did you know that there is a page called "uitest" which is comes enabled by default? You can see different elements on it. Good for testing your theme. Try it, http://localhost/atk4-example/?page=uitest

May 18thUse 10-columns instead of 12 by default

Give class="g-row" to your div and then inside that you can use classes like "g-4", "g-8" to slice the space horizontally. The total amount of values should be exactly 10. You can also use "g-max" for full-width column

May 11thDelete button is always last in grid

Adding some consistency by always moving column with delete button to be the last in grid.

Result

Name Surname Delete
vvvvvasdfsd asdfds
claudio norris
 

Code

$page->api->dbConnect();
$grid=$page->add('Grid');
$grid->addColumn('delete','delete');
$grid->addColumn('text','name');
$grid->addColumn('text','surname');
$grid->setSource('user');
$grid->dq->limit(5);

May 11thcolumn->setButtonClass

setButtonClass allows you to add additional class to Grid button.

Result

Name Salary B1 B2
John 2,000.00
Peter 4,200.00
Minus -200.00
 

Code

$grid=$page->add('Grid');
$grid->addColumn('text','name');
$grid->addColumn('money','salary');
$grid->addColumn('button','b1');
$grid->addColumn('button','b2')->setButtonClass('red ');
$grid->setStaticSource(array(
            array(
'name'=>'John','salary'=>'2000'),
            array(
'name'=>'Peter','salary'=>'4200'),
            array(
'name'=>'Minus','salary'=>'-200'),
            ));

May 8thadd getModel() to all views

You can now call setModel() and getModel() on any view. If you specify name of the model (string) to setModel() it will be instantiated and getModel() would always return object

May 8thGrid->getColumn

As you know, according to convention, add* methods return instance of a new column. Grid, however, does not add any objects when you use addColumn. It however remembers which column was last added and makes possible for such constructions:

$grid->addColumn('text','name')->makeSortable();

What if you didn't manage to make column sortable right away? Now there is getColumn function to help:

$grid->addColumn('text','name');
$grid->addColumn('text','surname');

$grid->getColumn('name')->makeSortable();

This is particularly helpful if you are using setModel() to initialize columns

May 5thDefault excetpion for form = validity check

Any object in Agile Toolkit has a exception() function. This function takes the string and returns new exception which you can throw. The primary reason for the function is syntactic sugar - you can chain calls on a function, while you can't chain if you use "new". Chaining of exceptions is used for adding more information. Remember that parameter for the exception() will be localized, and possibly displayed to user, while additional data can be passed for debugging.

Different objects can use different exceptions classes. Now function thrown Exception_ValidityCheck exception by default.

throw $form->exception('Message For User')
  ->
setField('fieldname')
  ->
addMoreInfo('foo',$bar);

There is another type of exception, called Exception_ForUser. Executing $page->exception() will trigger that instead.

May 2thadded button->isClicked() handler

Similarly how you can check form conditions, you can now do the same with buttons.

Result

 

Code

if($page->add('Button')->isClicked()){
    
$this->js()->univ()->alert('Random is: '.rand(1,100))->execute();
}


May 2thadded form->onSubmit()

Historically form would have a method onSubmit() which would return "true" when page was pulled from the form's "submit" AJAX request. With the release of PHP 5.3 closures are now available. onSubmit() method accepts one argument, a callable, which is executed right away if form is submitted. The benefit of this approach is that form will automatically capture validation errors and display them. You can also return JS from that function which would be executed automatically.

Result

 

Code

$form=$page->add('Form');
$form->setFormClass('vertical');
$form->addField('line','age');
$form->addSubmit();
$form->onSubmit(function($form){
    if(
$form->get('age')<5)
      throw 
$form->exception('Too young')
        ->
setField('age');

    return 
$form->js()->univ()->successMessage('thank you');
});

May 2thadded PathFinder's methods: search() and searchDir()

Pathfinder is here to search for resources. $api->locate() is one function you migth already know. $api->pathfinder->search() and searchDir() allows you to receive list of files in directories across multiple paths. Great for implementing dynamic plug-ins in your application.

Result

 

Code

$models=$this->api->pathfinder->searchDir('template',
    
'css');

$form=$page->add('Form');
$form->setFormClass('vertical');
$form->addField('dropdown','models')
    ->
setValueList($models);
$form->addfield('line','path');
$form->addfield('line','url');
$form->addSubmit('Resolve');

if(
$form->isSubmitted()){
    
$js=array(); $i=$form->get('models');
    
$js[]=$form->getElement('path')->js()->val($this->api->locate('template','css/'.$models[$i]));
    
$js[]=$form->getElement('url')->js()->val($this->api->locateURL('template','css/'.$models[$i]));
    
$form->js(null,$js)->execute();
}
Older Entries Newer Entries

Development History

All changes to the development version of Agile Toolkit are listed below.

Agile Toolkit Core
  • Release 4.2 NEW!
  • Release 4.1.2
  • August 2011
  • July 2011
  • June 2011
  • May 2011
  • April 2011
  • Mart 2011
  • February 2011

    • To stay up to date, by following @atk4 on twitter. Use Git / master branch for most recent version.