Skip to content

Latest commit

 

History

History
1236 lines (823 loc) · 36.8 KB

view.md

File metadata and controls

1236 lines (823 loc) · 36.8 KB

View

KumbiaPHP provides a presentation system, based on views which is the third component of the MVC system, as discussed in the section "Model, view, controller". The views are templates of code reusable that serve to show those data to the user and is found located in the directory app/views/.

It is good practice for development, containing the views of a minimum amount of code in PHP, so that it is sufficiently understandable for a Web Designer. To let the views, only the tasks display the results generated by the controllers and show catches of data to users.

Views handler implements the view design pattern in two steps, which is to divide the process to show a view in two parts: the first part is to use a view or «view» associated to a controller action to convert the data coming from the model into presentation logic without specifying any specific format and the second is to establish the format through a template or «template».

Also both the views of action and templates can be used 'partials' or partial views. These partial views are fragments of views that are shared by different views, so that they are reusable presentation logic into the application. Examples: menus, headers, footers, among others.

KumbiaPHP flavour convention for easy and faster programing. Views conventions:

  • All views files should have the suffix extension .phtml.
  • Each controller has an associated views directory whose name matches the name of the controller in smallcase notation. For example: If you have a controller whose class is called «PersonalTecnicoController» this Convention has a directory of views «personal_tecnico».
  • Whenever an action is executed will try to load a view whose name is the same as the action performed.
  • The templates must be located in the directory views/_shared/templates.
  • The partials should be located in the directory views/_shared/partials.
  • By default, the 'default' template is used to display views of action.

To indicate a different view assumed by convention method should be used View::select() on the controller. For example:

<?php  
class GreetingController extends AppController
 {  
    public function greeting()
   {   
           View::select('hello');   
    }  
}

In this way then that set the action «greeting» will be shown the view greeting/hello.phtml using the default template.

If you do not want to show a view, you must only pass NULL as an argument of View::select().

<?php  
class GreetingController extends AppController 
{  
    public function index()
    {   
           View::select(NULL);   
    }  
}  

To conclude this section, it should be noted that both the views of action, the templates and the partials are views, but comfort is often refer to the view action simply under the name of «view».

Send data to the view

To pass data to view these should be loaded as public attributes of the controller and after the action is executed, the views handler charged the public attributes of the controller as variables local level view. Example:

Controller: controllers/greeting_controller.php

<?php  
class GreetingController extends AppController
{  
    public function hello()
    {   
           $this->user= 'World' ;   
    }  
}  

View: views/greeting/hello.phtml

Hello <?php echo $user?>  

Output buffer

To display the contents of the output buffer is made using the View ::content() method, where the contents of the output buffer is mainly them echo or print to make the user and also the Flash messages. When you invoke View::content() shows the contents of the output buffer in the place where it was invoked.

Controller: greeting_controller.php

<?php  
class GreetingController extends AppController 
{  
    public function hello()
    {   
           Flash::valid('Hello World);   
    }  
}  

View: views/greeting/hello.phtml

Do greeting:  
<?php View::content() ?>  

Template

The templates are the layer more outside of the view which will be displayed after running an action of the controller, so that it allows to set the format appropriate for the view.

When speaking of format does not refer only to the document type, if not also to elements such as headers and menus. Therefore the template is made up of those elements that as a whole they are used for the presentation of different views, giving thus a reusable format.

How to create a template?

To build a new template, you must create a file with extension .phtml in views/_shared/templates/ directory , which must correspond with the name of the template.

As previously explained at the beginning of the chapter "The view", view handler uses "view in two steps" design pattern. In the first step, is processed in view of action, then the action view rendered is stored in the output buffer and the template is processed in the second step.

Consequently, as processed action view is stored in the output buffer is necessary to invoke the method View::content() in the place where you want to display the view. Look "Output buffer" section.

Example:

views/_shared/templates/example.phtml

<!DOCTYPE html>  
<html>  
<head>  
   <title>Example Template</title>  
</head>  
<body>  
   <h1>Example Template</h1>  

    <?php View::content() ?>   
</body>  
</html>  

How to use a template?

To select the template to use you must invoke the method View::template() passing as an argument to the template to use. Example:

Controller:

<?php  
class GreetingController extends AppController 
{  
    public function hello()
    {   
           // Select template 'example.phtml'   
           View::template('example');   
    }  
}  

It is also possible to indicate to views that you do not use any template and therefore only show the view, for this you should pass NULL as an argument to View::template().

<?php  
class GreetingController extends AppController 
    {  
    public function hello(){   
           // Do not use template   
           View::template(null);   
    }  
}  

Send data to the template

As discussed in the section "Send data to the view," the public attributes of the controller are loaded as variables local scope in view. As show the template, it is the second step to show the full view, the public attributes of the controller will be similarly charged as local scope in the template variables. Example:

In the greeting_controller.php controller

<?php  
class GreetingController extends AppController {  
    public function hello(){   
           Flash::valid('Hello World');   

            // Pass the title to the page   
           $this->title= 'Greeting to the world';   

            /* No view will not be used, therefore 
            the output will be the buffer and the template */   
           View::select(null, 'greeting');   
   }  
}  

In the greeting.phtml template

<!DOCTYPE html>  
<html>  
<head>  
   <title> <?php echo $title ?></title>  
</head>  
<body>  
   <h1>Greeting Template</h1>  

    <?php View::content() ?>   
</body>  
</html>  

Partial

Partials or "partial views" are fragments of views that are shared by different views, so they are reusable presentation logic in the application. The partials are usually items like: menus, header, footer of page, forms, among others.

How to create a partial?

To build a new partial you must create a file with extension .phtml in the directory views/_shared/partials/ which must correspond with the name of the partial.

Example:

views/_shared/partials/header.phtml

<h1>Greeting Template</h1>  

How to use a partial?

To use a partial method should invoke the View::partial() as an argument indicating the desired partial. The partial view is displayed in the place where it was invoked.

Example using a partial in a template:

<!DOCTYPE html>  
<html>  
<head>  
   <title>Example</title>  
</head>  
<body>  
    <?php View::partial('header') ?>   

    <?php View::content() ?>   
</body>  
</html>  

Importantly, the partial can be used both in view of action, templates and even within other partials.

Send data to the partials

To pass data to a partial, these must be in an associative array where each key with the corresponding value was loaded as a variable in the local scope of the partial.

Example:

views/partials/header.phtml

<h1>Title: <?php echo $title ?></h1>  

views/example/index.phtml

<?php  View::partial('header' , false, array('title' =>'Example'))
?>  

<p>  
This is an example
</p>  

Grouping in directories

In KumbiaPHP views, partials and templates can be grouped into directories, using the spacer «/» in the route.

Example of grouping views

View views/user/advertisement/form.phtml, is used follows in the controller:

<?php  
class UserController extends AppController 
{  
    public function new()
    {   
           // Select the view
           View::select('advertisement/form');   
    }  
}  

Example of grouping of partial

The partial views/_shared/partials/user/form.phtml, is used in the following manner either in view or template:

<h1>New User</h1>  
<?php View::partial('user/form') ?>  

Example of grouping of template

The template views/_shared/templates/user/admin.phtml, is used follows in the handler:

<?php  
class AdministratorController extends AppController 
{  
    protected function before_filter()
    {   
           // Select the template   
           View::template('user/admin');   
    }  
}  

Response types

The types of responses are used to establish various view formats. For example: xml, json and pdf.

To establish a kind of response you must invoke the method View::response() indicating the desired response, once indicating the type of response this is automatically placed as extension of the view file. Therefore use answers types as a whole to the template are a powerful tool for generation of view full user.

Example:

<?php  
class UserController extends AppController 
{  
    public function index()
    {   
           // Set reponse type 
           View::response('json');   
    }  
}  

In this example, the index.json.phtml view will be shown.

Use of cache in views

Views handler provides mechanisms through which the views, the partials and the templates can be cached. The user indicates the time during which they will be stored in the cache so that views handler will load these items without having to process them, increasing the performance of your application.

In this sense to indicate cache time is PHP strtotime function format. Example: '+ 1 week';

Cache views

To cache a view the View::cache() method is used in the controller.

<?php  
class UserController extends AppController 
{  
    public function index()
    {   
           // Indicates time view cache
           View::cache('+20 days');   
    }  
}

Note that the action runs on the controller because the data passed to the view may likewise be required in the template.

Groups of views in cache

You can store the cached views in groups. The groups are very interesting, since you can delete the cache by groups also. Example: Save cache posts in a group, to create, edit, or delete a post, we can delete the cache of that group, so to regenerate the cache.

In this case it is necessary to indicate in the View::cache() method will cache a view to a specific group.

<?php  
class UserController extends AppController 
{  
    public function index()
    {   
           // Indicates time view cache  
           View::cache('+20 days' ,'view' ,'myGroup');   
    }  
}  

Cache templates

Cache a template consists of cache altogether both the view and template for a specific URL. The View::cache() method is used to cache a template in the controller indicating the time during which will be cached template.

<?php  
class UserController extends AppController 
{  
    public function index()
    {   
           // Indicates time template cache
           View::cache('+20 days' , 'template');   
    }  
}  

Should be noted that to increase performance not executes the action in the controller, since show the template is the last step that performs views handler to display the view to the user and this step already all data sent to the view and template have been used.

Cache of partials

To cache partials should be indicated as the second argument to invoke View::partial() the time during which will be stored in the cache.

<?php  View::partial('user' ,'+1 day') ?>    
<?php  View::partial('user' ,'+1 day' ,array('name'=>'john')) ?>  

Helpers

Helpers are used in the views. Encapsulate code in methods for easy reuse.

KumbiaPHP already comes with helpers created.

But what really useful, is that users can create their own helpers and place them into extensions/app/helpers /. And then using them quietly in their views. KumbiaPHP transparently load their helpers as well as you use them.

Html

Class with methods static that we create optimized HTML tags respecting KumbiaPHP conventions.

Html::img()

It allows you to include an image

$src image path

$alt attribute alt for image

$attrs additional attributes

Html::img ($src, $alt = NULL, $attrs = NULL)

<br />/ * Example * / 

echo Html:img('spin.gif'_,'an_imagen');   //the image spin.gif located inside of "/ public/img /"
//with alt artibute 'an image'  

Html::link()

It allows you to include a link

$action path to action

$texto text to show

$attrs additional attributes

Html::link ($action, $text, $attrs = NULL)

/ * Example * / 
echo html:link('pages/show/kumbia/status'_,'Configuration'); //shows a link with the text 'Configuration'  

Html::lists()

It creates a html list from an array

$array contents of the list

$type default ul, and not ol

$attrs additional attributes

HTML:lists($array_,$type_=_'ul'_,$attrs_=_NULL) 

/* example */

$ar = array ('Belly' => 'Belly', 'Arms' => 'Arms', 'Head' => 'Head', 'Neck' => 'Neck', 'Genitals' => 'Genital', 'Legs' => 'Legs', 'Chest' => 'Chest', 'Other' => 'Other'); $ar the array containing the items of the list. echo Html:lists($ar,$type=_'ol'); //Displays a list

$ar2 = array('Belly', 'Arms', 'Head', 'Neck', 'Genitals', 'Legs', 'Chest', 'Other'); echo Html: lists ($ar2, $type = ' ol'); //Displays a list

<br />#### Html::gravatar()

Includes images from gravatar.com

$email Email to get your gravatar

$alt Alternative text of the image By default: gravatar

$size size of the gravatar. A number from 1 to 512. By default: 40

$default URL gravatar by default if not exists, or a default of gravatar. HTML: gravatar($email, $alt='gravatar', $size=40, $default='mm')

echo Html:gravatar ($email); //Simple
echo Html:link (Html:gravatar ($email), $url); //A gravatar that is a link
echo Html:gravatar($email_,$name_,_20_,_'http://www.example.com/default.jpg'); //Full   

Html::includeCss()

Includes the CSS files that were previously loaded to the list using the Tag::css()

Tag:css('welcome'); //Put in list a CSS (app/public/css/welcome.css)
echo Html:includeCss; //Add linked resources of the class in the project   

Html::meta()

Creates a metatag and adds it to a static list that will be added later through Html:includeMetatags();

$content the metatag content

$attrs additional attributes of the tag

Html::meta($content, $attrs = NULL)

HTML:meta('Kumbiaphp-team'_,"name_=_'Author'");  
//Added: <meta content = "Kumbiaphp-team" name = 'Author' />
Html:meta('text/html;_charset=UTF-8'_,"http-equiv_=_'Content-type'");
//Added: <meta content = "text/html; Charset = UTF-8 "http-equiv = 'Content-type' />  

Html::includeMetatags()

Add the metatag that previously it had added

Html::meta( 'Kumbiaphp-team' , "name = 'Author'") ;
Html::meta( 'text/html; charset=UTF-8' , "http-equiv = 'Content-type'") ;
echo Html::includeMetatags () ;   //Display <meta content="Kumbiaphp-team" name = 'Author'/>

Html::headLink()

Adds an element of link type external [

](http://html.conclase.net/w3c/html401-es/struct/links.html#h-12.3) to the tail of links (to be able to be displayed is required HTML::includeHeadLinks() in a similar way to Html::includeCss()))

$href address url of the resource to link

$attrs additional attributes

Html::headLink($href, $attrs = NULL)  

Html::headlink('http://www.kumbiaphp.com/public/style.css', "rel='stylesheet',type='text/css' media='screen'");
//The link to an external resource is added to the link queue, in this case the style sheet located in "http://www.kumbiaphp.com/public/style.css"

/*Add to link queue "<link rel="alternate" type="application/rss+xml"
title="KumbiaPHP Framework RSS Feed" href="http://www.kumbiaphp.com/blog/feed/" />" With which we can include a feed without using the conventions of kumbiaphp */

Html::headlink('http://www.kumbiaphp.com/blog/feed/', "rel='alternate'
type='application/rss+xml' title='KumbiaPHP Framework RSS Feed'");

Html::headlink('http://www.kumbiaphp.com/favicon.ico' , "rel='shortcut
icon',type='image/x-icon'");   //Agrega la etiqueta <link> To use an external favicon

echo  Html::includeHeadLinks();   //Show the links in the queue  

HTML::headLinkAction()

Adds an element of link type external [

](http://html.conclase.net/w3c/html401-es/struct/links.html#h-12.3) to the tail of links (to be able to be displayed is required HTML::includeHeadLinks() in a similar way to Html::includeCss()))

$href address url of the resource to link

$attrs additional attributes

Html::headLinkAction($action, $attrs = NULL)

/*Add to link queue "<link rel="alternate" type="application/rss+xml"
title="KumbiaPHP Framework RSS Feed" href="http://www.kumbiaphp.com/blog/fee
d/" />" With which we can include a feed using KumbiaPHP conventions.
Being 'articles/feed' the name of the view with the content of the feed */

Html::headLinkAction('articles/feed', "rel='alternate'
type='application/rss+xml' title='KumbiaPHP Framework RSS Feed'");
echo  Html::includeHeadLinks();   //Displays the links in the queue  

Html::headLinkResource()

Adds an element of link type external [

](http://html.conclase.net/w3c/html401-es/struct/links.html#h-12.3) to the tail of links (to be able to be displayed is required HTML::includeHeadLinks() in a similar way to Html::includeCss()

$resource location of the resource in public

$attrs additional attributes

Html::headLinkResource($resource, $attrs = NULL)

//Added tag <link> To use an internal favicon located in the directory '/public/'
Html::headLinkResource('favicon.ico', "rel='shortcut
icon', type='image/x-icon'");   
echo Html::includeHeadLinks();   //Shows the links in the queue  

Html::includeHeadLinks()

It includes the links that were previously put in queue

Html::headlink('http://www.kumbiaphp.com/favicon.ico', "rel='shortcut
icon', type='image/x-icon'");   //Add <link> tag to use external favicon

Html::headLinkAction('articulos/feed', "rel='alternate' type='application/rss+xml' title='KumbiaPHP Framework RSS Feed'");
echo  Html::includeHeadLinks();  

Tag

This class will allow us to add JS and CSS files to our project, either files that are on our server or on an external server.

The functions of this class are of type static, allowing us to use them directly from the form as below.

Tag::css()

Includes a CSS file to the list

Tag:css('welcome'); //Put in list a CSS (app/public/css/welcome.css)
echo Html:includeCss; //Add linked resources of the class in the project   

Tag::js()

It includes a JavaScript file to view, partial or template

<?= Tag:js('jquery/jquery.kumbiaphp'); //Adds a javascript file (/ app/public/javascript/jquery/jquery.kumbiaphp.js)? >  

Class Form

Class for managing and creating forms

Form::open()

It creates a form tag

$action action that sends data, by default calls the same action where it comes from

$method 'POST', 'GET', 'DELETE', 'HEAD' AND 'PUT'. By default it is 'POST'

$attrs additional attributes

Form::open($action = NULL, $method = 'POST', $attrs = NULL)

/*Ejemplo*/  
<?= Form::open() ?> //Starts a form that will send the data to the action that corresponds to the current controller
<?= Form::open('users/new') ?>  //Starts a form that will send the data to the 'users' controller and the 'new' action  

Form::openMultipart()

Create a multipart form tag, this is ideal for forms that contain fields for file uploads

$action action that sends data, by default calls the same action where it comes from

$attrs additional attributes

Form::openMultipart ($action = NULL, $attrs = NULL)

/*Example*/
//Starts a multipart form that will send the data to the action corresponding to the current view
echo Form::openMultipart();
//Starts a multipart form that will send the data to the 'users' controller and the 'new' action
echo Form::openMultipart('users/new');

Form::close()

Create a closing form tag

/*Example*/
echo Form::close();
//create form close tag  </form>  

Form::input()

Create a field of type input

$attrs attributes to the tag

$content internal content

Form::input($attrs = NULL, $content = NULL)

/* Example */
echo Form: input('name');  

Form::text()

Create a field of type input

That gives the name of the form parameter model.field, i.e. a name containing a point within the string is always created the text field with the name="model[field]" and id="model_field".

$field field name

$attrs field attributes

$value value initial for the input

Form::text($field, $attrs = NULL, $value = NULL)

/ * Example * / 
//create a input of type text with the parameter name="name", id="name" 
echo Form:text('name');
//creates a input of type text with the parameter name="user[name]", id="usuario_nombre"
echo Form:text('usuario.nombre');
//creates a input of type text with the parameter name="name", id="name", class="box", value="55"
echo Form:text('nombre', "class='caja'", '55');   

Form::pass()

It creates a Password type input

$field field name

$attrs field attributes

$value value initial for the input

Form::pass($field, $attrs = NULL, $value = NULL)

/* Example */
echo Form:pass('password'); //creates a field of type password  with the name parameter name='password'  

Form::textarea()

Creates a textarea

$field field name

$attrs field attributes

$value value initial for the textarea

Form::textarea($field, $attrs = NULL, $value = NULL)

echo Form::textarea('details'); //Creates a textarea  

Form::label()

Creates a label and associates it to a field

$texto text to show

$field field to which reference is made

$attrs array of optional attributes

Form::label($text, $field, $attrs = NULL)

//Creates a label for the field name with the text ' User Name:'
echo Form:label('User Name:', 'name');
echo Form:text('name');  

Form::hidden()

Creates a hidden field

$field field name

$attrs additional attributes of the tag

$value value initial for the hidden input

Form::hidden($field, $attrs = NULL, $value = NULL)

echo Form:hidden('id',_null,_12);  //Creates a hidden field with the name="id" and value="12"  

Form::dbSelect() (Deprecated)

Creates a Select field that retrieves values from ActiveRecord objects. In this version of the framework, the use of this helper has been simplified. It is no longer necessary to instantiate the model.

Argument Description
$field Name of the model and primary key field (under the convention model.field_id)
$show Field to be displayed
$data Array of values, array('model', 'method', 'param')
$blank Empty field
$attrs Field attributes
$value Initial value for the field

The dbSelect() method will be marked as deprecated; therefore, its use is no longer recommended.

Reasons:

  • It's an unnecessary magic method.
  • It's not very explicit.
  • It's slower than directly using select().
  • It's completely coupled with the old Kumbia AR and cannot be used with other ORMs; it doesn't work with the new ActiveRecord.

More usage examples to replace Form::dbSelect() can be found in the next section on Form::select().


Form::dbSelect($field, $show = NULL, $data = NULL, $blank = NULL, $attrs =
NULL, $value = NULL)  

Example

In the view:

// the simplest way, loads the model(field) and displays the first field after the pk(id)
echo Form::dbSelect('users.field_id');
// displays the field and sorts it in ascending order    
echo Form::dbSelect('users.field_id', 'field');  

Form::select()

Creates a select field (a combobox)

Argument Description
$field Field name
$data Array of values for the dropdown list
$attrs Field attributes
$value Initial value for the field

Form::select($field, $data, $attrs = NULL, $value = NULL)

Examples

In KumbiaPHP, you can define constants within your models to represent data that won't change during the application's execution. Constants are especially useful for defining fixed options such as category listings, user roles, or, in this case, farm names. This is done using the const keyword within a model class.

<?php

class Reservations extends ...
{
  const FARM = [
    1 => 'South',
    2 => 'North'
  ];
...

Here, Reservations is a model that can optionally extend from a class of your favorite ORM. The FARM constant is defined as an associative array, making it easier to maintain and access these static values across the application.

In the form view

// Uses the FARM constant from the Reservations class
<?= Form::select('reservations.farm_id', Reservations::FARM) ?>

In this snippet:

'reservations.farm_id' specifies the field name in the form. This will be used on the server to identify the value selected by the user.

Reservations::FARM passes the array defined in the Reservations model as the options for the <select>. KumbiaPHP automatically generates the select options using the array keys as the value attribute values and the array values as the visible text.

Result:

<select id="reservations_farm_id" name="reservations[farm_id]">
    <option value="1">South</option>
    <option value="2">North</option>
</select>

To display the farm information in the view:

<?= "Farm ". Reservations::FARM[$reservation->farm_id] ?>

In KumbiaPHP, the Form::select() helper is used to create an HTML <select> field easily and efficiently. Here's how to use this helper along with the PHP range() function to generate a numeric list of options.

Example Using Form::select() with Function or Method Results

The PHP code:

<?= Form::select('reservations.pax', range(0, 8)) ?>

Explanation:

  • Form::select('reservations.pax', range(0, 8)): This code generates a <select> field with the name reservations.pax.
  • The range(0, 8) function in PHP creates an array that includes numbers from 0 to 8. These numbers are used by Form::select() to create the select field options.

The HTML generated by this code will be as follows:

<select id="reservations_pax" name="reservations[pax]">
    <option value="0">0</option>
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    <option value="6">6</option>
    <option value="7">7</option>
    <option value="8">8</option>
</select>

This approach is particularly useful for form fields where consecutive numeric values are needed, such as selecting the number of passengers, ratings, or any other limited numeric range. It simplifies implementation without needing to hard-code each option manually.

Using Arrays of Objects with Form::select()

In web application development using ORMs (Object-Relational Mapping), a common practice is to retrieve data from the database as arrays of objects. This makes it easier to handle data in the context of object-oriented programming. KumbiaPHP, like many other modern frameworks, allows you to use this data directly to efficiently build form elements.

Below is how to use this helper with different ways of obtaining an array of objects from a model named Farms.

Example 1: Object Instance

<?= Form::select('reservations.farm_id', (new Farms)->mySelect()) ?>
  • (new Farms)->mySelect(): Here, an instance of the Farms model is created, and the mySelect() method is called on that instance. This method should be defined in the Farms model and configured to return an array of objects, each representing a possible option for the <select>.

Example 2: Static Method

<?= Form::select('reservations.farm_id', Farms::mySelect()) ?>
  • Farms::mySelect(): In this variant, mySelect() is a static method of the Farms class. This means it's not necessary to create an instance of the model to call this method. Similar to the previous example, this method should return an array of objects.

Example 3: Static Method with Parameters

<?= Form::select('reservations.farm_id', Farms::mySelect(param1, param2, ...)) ?>
  • Farms::mySelect(param1, param2, ...): Here, the mySelect() method is also static but is called with one or more parameters. These parameters can influence how the database query is generated, allowing customization of the returned object array. For instance, they could determine which farms are returned based on criteria such as location, size, or availability.

HTML Output

The HTML generated by any of these code examples will look like this, assuming that the mySelect() method returns an array where each object has id and name properties:

<select id="reservations_farm_id" name="reservations[farm_id]">
    <option value="1">Farm La Estancia</option>
    <option value="2">Farm El Retiro</option>
    <!-- more options based on what mySelect() returns -->
</select>

Form::file()

Create field File to upload files, the form must open with Form::openMultipart()

$field name of field

$attrs attributes of field

Form::file($field, $attrs = NULL)

echo Form::openMultipart();   //Opens the multipart form
echo Form::file('subir');  //Creates a field to upload files
echo Form::close();   //Closes the form  

Form::button()

Create a button

$text button text

$attrs button attributes

Form::button($text, $attrs = NULL)

echo Form::button('calculate');   // Create a button with the text 'calculate'  

Form::submitImage()

Create an image button following the KumbiaPHP conventions, the image should be inside the directory '/public/img'

$img path to the image to use on the button

$attrs button attributes

Form::submitImage($img, $attrs = NULL)

echo Form::submitImage('buttons/edit.gif');   // Create a button with the image 'buttons/edit.gif'  

Form::submit()

Create a submit button for the current form

$text Button text

$attrs Button attributes

Form::submit($text, $attrs = NULL)

echo Form::submit('send');   //Create a button with the text 'send'  

Form::reset()

Create a reset button for the current form

$text Button text

$attrs Button attributes

Form::reset($text, $attrs = NULL)

echo Form::reset('reset');   // Create a button with the text 'reset'  

Form::check()

Create a checkbox

$field Name of field

$value Checkbox value

$attrs Field attributes

$checked indicates if the field is checked

Form::check($field, $value, $attrs = NULL, $checked = NULL)

// Create a checked box with id="remember" , name="remember" and value="1"
echo  Form :: check ( 'remember' , '1' , '' , true ) ;  
// Create an UNchecked box with id="remember" , name="remember" and value="1"
echo  Form :: check ( 'remember' , '1' , '' , false ) ;     

Form::radio()

Create a radio button

$field Name of field

$value Radio button value

$attrs Attributes of field

$checked Indicates if the field is checked

Form::radio($field, $value, $attrs = NULL, $checked = NULL)

$on   =   'masculine' ;
//<input id="rdo1" name="rdo" type="radio" value="masculine" checked="checked">
echo Form::radio("rdo", 'masculine', null, true);  
//<input id="rdo2" name="rdo" type="radio" value="feminine">  
echo Form::radio("rdo", 'feminine');

Js

This helper offers some implementations using simple javascript.

Js::link ()

Create a link which upon pressing will display a confirmation dialog to redirect to the indicated path.

$action Path to the action

$text Text to show

$confirm Confirmation message

$class Additional classes for the link

$attrs $attrs Additional attributes

Js::link ($action, $text, $confirm = 'Are you sure?', $class = NULL, $attrs = NULL)

<?= Js::link('user/delete/5', 'Delete') ?>  

If you'd like to apply a style class to the link you must specify it in the $class argument.

<?= Js::link('user/delete/5', 'Delete', 'Are you sure you want to do this?', 'b_delete') ?>  

Js::linkAction ()

Create a link which upon pressing will display a confirmation dialog to redirect to the indicated action.

$action Controller action

$text Text to show

$confirm Confirmation message

$class Additional classes for the link

$attrs $attrs Additional attributes

Js::linkAction ($action, $text, $confirm = 'Are you sure?', $class = NULL, $attrs = NULL)

<?php echo Js::linkAction('delete/5', 'Delete'); ?>  
//If you want to apply a style class to the link you must indicate so in the $class argument
<?php echo Js::linkAction('delete/5', 'Delete', 'Are you sure you want to do this?', 'b_delete') ?>  

Js::submit ()

Create a submit button that shows a confirmation dialog when you press it.

$text Text to show

$confirm Confirmation message

$class Additional classes for the link

$attrs Additional attributes

Js::submit ($text, $confirm = 'Are you sure?', $class = NULL, $attrs = NULL)

<?php echo Js::submit('Save') ?>  
// If you'd like to apply a style class to the link you must specify it in the $class argument.
<?= Js::submit('Save', 'Are you sure?', 'save_button') ?>  

Js::submitImage ()

Create an image button that when pressed displays a confirmation dialog.

$img Path to image

$confirm Confirmation message

$class Additional classes for the link

$attrs Additional attributes

Js::submitImage($img $confirm = 'Are you sure?', $class = NULL, $attrs = NULL)

<?php echo Js::submitImage('buttons/save.png') ?>  
//If you want to apply a style class to the link you must indicate so in the $class argument.
<?= Js::submitImage('buttons/save', 'Are you sure?', 'save_button') ?>  

Ajax

This helper provides implementations to make AJAX integration easy.

Ajax::link()

Create a link to update the indicated layer with the content of the web request.

$action Path to action

$text Text to show

$update Layer to update

$class Additional classes

$attrs Additional attributes

Ajax::link ($action, $text, $update, $class=NULL, $attrs=NULL)

As an example, it creates a link that pressing displays a greeting. The following configurable views and controllers are:

controllers/greeting_controller.php

<?php
class GreetingController extends AppController
{
    public function index()
    {}

    public function hello()
    {
        View::template(NULL);
    }
}  

views/greetings/hello.phtml

Hello

views/greetings/index.phtml

<div id="greeting_layer"></div>
<?php
    echo Ajax::link('greeting/hello', 'Show Greeting', 'greeting_layer');
    echo Tag::js('jquery/jquery+kumbiaphp.min');
?>  

To access the action greeting controller's layer:

After clicking the link it's placed the ajax request's result in the layer.

Ajax::linkAction()

Create a link to a current controller action which updates the layer indicated by the content of the web request.

$action action

$text Text to show

$update Layer to update

$class Additional classes

$attrs Additional attributes

Ajax::linkAction ($action, $text, $update, $class=NULL, $attrs=NULL)

<?= Ajax::linkAction('Hello', 'Show Greeting', 'greeting_layer') ?>  

Of course... This documentation is still missing, for the moment it's recommended to revise CRUD from version 1.0 beta 2 where you can see other changes, these are documented very soon. CRUD Beta2 KumbiaPHP