Thứ Năm, 24 tháng 4, 2014

The HeadTitle helper [Chat and E-mail]

he HeadTitle helper is used trender title in the <title> tags on the HTML head section; multiple calls to a headTitle() helper create a list of titles which arrendered when tag is outputted in the layout/view. The optional parameter $setType can be setoverride the pre-existing array of titles, the default is APPEND, it can be overridden tPREPEND or SET(overwrite).

The syntafor this helper is headTitle($title, $setType = null);.
In this task we will be converting some of our existing pages to make use of the jQuery UI library and render buttons in that page using jQuery UI:

1.       View the existing application home page as shown in the following screenshot; our nextask is tconvert the Login and Register linktrender as jQuery UI buttons:


2.       Replace the Login and Register links in the index view (module/Users/view/ users/index/index.html), and add the ui-button class to the links as shown in the following code snippet:
<a href="/users/login" class='ui-button'>Login</a>
<a href="/users/register" class='ui-button'>Register</a>

3.       Add external references to jQuery UI towards the beginning of the view:
// Attached jQuery UI Scripts
$this->headScript()

$this->headScript()
js','text/javascript');

// Attach jQuery UI Styles
$this->headLink()->appendStylesheet('http://code.jquery.com/ ui/1.10.0/themes/base/jquery-ui.css');
4.       Add a UI initialization scripto apply the button look and feel to both the links:
// UI Initializer for buttons
$this->headScript()->appendScript( '$(function() {
$("a.ui-button").button();
});', 'text/javascript');
5.       Preview the home page in the browser now, and you will be able to see thaboth the Login and Register buttons arstyled using jQuery UI as shown in the following screenshot:


A View Source link on the index page will reveal the application of headScript() as shown in the following code:

<!DOCTYPE html>
<html lang="en">
...
...
<script type="text/javascript">
//<!--


$(function() {
$("a.ui-button").button();
});
//-->
</script>
...
...
</html>


What just happened?
We have made use of Zend Framework's view helpertconnect to the external JavaScript library; we then added custom JavaScripto the HTML head section using the headScript() view helper.

Nowe have integrated our application with an external JavaScript; in the nexexercise we will learn a little bit more on how scripts can be added to the HTML head section.

Beforwe move on to building the Group Chat interface, here is a simple task for you tcomplete. Now thayou have understood how to link external JavaScript libraries, you can download jQuery UI from its website, extract itto the public/ folder, and modify the previously listed pagto use the downloaded version of jQuery UI. jQuery UI can be downloaded from http://jqueryui.com/.

Không có nhận xét nào:

Đăng nhận xét