Zend Framework – Installation

Zend Framework – Installation ”; Previous Next To install the Zend Framework, we must first install the Composer and the latest version of PHP as shown in the following steps. Install Composer − Zend uses Composer for managing its dependencies, so make sure you have the Composer installed on your machine. If the Composer is not installed, then visit the official website of Composer and install it. Install the latest version of PHP − To get the maximum benefit of Zend Framework, install the latest version of PHP. The minimum required version for the Zend Framework 3 is PHP 5.6 or later. Install Zend Framework Zend Framework can be installed in two ways. They are as follows − Manual installation Composer based installation Let us discuss both these installations in detail. Manual Installation Download the latest version of Zend Framework by visiting the following link – https://framework.zend.com/downloads/archives Extract the content of the downloaded archive file to the folder you would like to keep it. Once you have a copy of Zend Framework available in your local machine, your Zend Framework based web application can access the framework classes. Though there are several ways to achieve this, your PHP include_path needs to contain the path to the Zend Framework classes under the /library directory in the distribution. This method applies to Zend Framework version 2.4 and earlier only. Composer Based Installation To easily install the Zend Framework, use the Composer tool. This is the preferred method to install the latest version of Zend Framework. To install all the components of the Zend Framework, use the following Composer command − $ composer require zendframework/zendframework Each Zend Framework module / component can be installed individually as well. For example, to install the MVC component of the Zend Framework, use the following composer command − $ composer require zendframework/zend-mvc Print Page Previous Next Advertisements ”;

Zend Framework – Service Manager

Zend Framework – Service Manager ”; Previous Next The Zend Framework includes a powerful service locator pattern implementation called zend-servicemanager. Zend framework extensively uses the service manager for all its functionalities. The Service Manager provides a high-level abstraction for the Zend Framework. It also integrates nicely with all the other components of the Zend Framework. Install Service Manager The Service Manager component can be installed using the composer tool. composer require zendframework/zend-servicemanager Example First, all the services need to be registered into the service manager. Once the services are registered into the server manager system, it can be accessed at any time with minimal efforts. The service manager provides a lot of options to register the service. A simple example is as follows − use ZendServiceManagerServiceManager; use ZendServiceManagerFactoryInvokableFactory; use stdClass; $serviceManager = new ServiceManager([ ”factories” => [stdClass::class => InvokableFactory::class,], ]); The above code registers the stdClass into the system using the Factory option. Now, we can get an instance of the stdClass at any time using the get() method of the service manager as shown below. use ZendServiceManagerServiceManager; $object = $serviceManager->get(stdClass::class); The get() method shares the retrieved object and so, the object returned by calling the get() method multiple times is one and the same instance. To get a different instance every time, the service manager provides another method, which is the build() method. use ZendServiceManagerServiceManager; $a = $serviceManager->build(stdClass::class); $b = $serviceManager->build(stdClass::class); Service Manager Registration The service manager provides a set of methods to register a component. Some of the most important methods are as given below − Factory method Abstract factory method Initializer method Delegator factory method We will discuss each of these in detail in the upcoming chapters. Factory Method A factory is basically any callable or any class that implements the FactoryInterface (ZendServiceManagerFactoryFactoryInterface). The FactoryInterface has a single method − public function __invoke(ContainerInterface $container, $requestedName, array $options = null) The arguments details of the FactoryInterface is as follows − container (ContainerInterface) − It is the base interface of the ServiceManager. It provides an option to get other services. requestedName − It is the service name. options − It gives additional options needed for the service. Let us create a simple class implementing the FactoryInterface and see how to register the class. Class Test – Object to be Retrieved use stdClass; class Test { public function __construct(stdClass $sc) { // use $sc } } The Test class depends on the stdClass. Class TestFactory – Class to Initialize Test Object class TestFactory implements FactoryInterface { public function __invoke(ContainerInterface $container, $requestedName, array $options = null) { $dep = $container->get(stdClass::class); return new Test($dep); } } The TestFactory uses a container to retrieve the stdClass, creates the instance of the Test class, and returns it. Registration and Usage of the Zend Framework Let us now understand how to register and use the Zend Framework. serviceManager $sc = new ServiceManager([ ”factories” => [stdClass::class => InvokableFactory::class, Test::class => TestFactory::class] ]); $test = $sc->get(Test::class); The service manager provides a special factory called InvokableFactory to retrieve any class which has no dependency. For example, the stdClass can be configured using the InvokableFactory since the stdClass does not depend on any other class. serviceManager $sc = new ServiceManager([ ”factories” => [stdClass::class => InvokableFactory::class] ]); $stdC = $sc->get(stdClass::class); Another way to retrieve an object without implementing the FactoryInterface or using the InvokableFactory is using the inline method as given below. $serviceManager = new ServiceManager([ ”factories” => [ stdClass::class => InvokableFactory::class, Test::class => function(ContainerInterface $container, $requestedName) { $dep = $container->get(stdClass::class); return new Test($dep); }, ], ]); Abstract Factory Method Sometimes, we may need to create objects, which we come to know only at runtime. This situation can be handled using the AbstractFactoryInterface, which is derived from the FactoryInterface. The AbstractFactoryInterface defines a method to check whether the object can be created at the requested instance or not. If object creation is possible, it will create the object using the __invokemethod of the FactoryInterface and return it. The signature of the AbstractFactoryInterface is as follows − public function canCreate(ContainerInterface $container, $requestedName) Initializer Method The Initializer Method is a special option to inject additional dependency for already created services. It implements the InitializerInterface and the signature of the sole method available is as follows − public function(ContainerInterface $container, $instance) function(ContainerInterface $container, $instance) { if (! $instance instanceof EventManagerAwareInterface) { return; } $instance->setEventManager($container->get(EventManager::class)); } In the above example, the method checks whether the instance is of type EventManagerAwareInterface. If it is of type EventManagerAwareInterface, it sets the event manager object, otherwise not. Since, the method may or may not set the dependency, it is not reliable and produces many runtime issues. Delegator Factory Method Zend Framework supports delegators pattern through DelegatorFactoryInterface. It can be used to decorate the service. The signature of this function is as follows − public function __invoke(ContainerInterface $container, $name, callable $callback, array $options = null ); Here, the $callback is responsible for decorating the service instance. Lazy Services Lazy service is one of those services which will not be fully initialized at the time of creation. They are just referenced and only initialized when it is really needed. One of the best example is database connection, which may not be needed in all places. It is an expensive resource as well as have time-consuming process to create. Zend framework provides LazyServiceFactory derived from the DelegatorFactoryInterface, which can produce lazy service with the help of the Delegator concept and a 3rd party proxy manager, which is called as the ocramius proxy manager. Plugin Manager Plugin Manager extends the service manager and provides additional functionality like instance validation. Zend Framework extensively uses the plugin manager. For example, all the validation services come under the ValidationPluginManager. Configuration Option The service manager provides some options to extend the feature of a service manager. They are shared, shared_by_default and aliases. As we discussed earlier, retrieved objects are shared among requested objects by default and we can use the build() method to get a distinct object. We can also use

Zend Framework – Discussion

Discuss Zend Framework ”; Previous Next Zend is an open source PHP framework. It is pure object-oriented and built around the MVC design pattern. Zend framework contains collection of PHP packages which can be used to develop web applications and services. Zend was started by Andi Gutmans and Zeev Suraski. This tutorial will give you a quick introduction to Zend Framework and make you comfortable with its various components. Print Page Previous Next Advertisements ”;

Email Management

Zend Framework – Email Management ”; Previous Next The Zend Framework provides a separate component called as zend-mail to send email messages. The zend-mail component also provides an option to read and write email messages with attachments both in text and html format. Sending an email in Zend is much easier and simple to configure. Let us go through the email concepts, basic settings, advanced settings such as SMTP transport, etc., in this chapter. Install Mail Component The mail component can be installed using the following Composer command. composer require zendframework/zend-mail Basic Email Configuration A basic email consists of one or more recipients, a subject, a body and a sender. Zend provides ZendMailMessage class to create a new email message. To send an email using the zend-mail, you must specify at least one recipient as well as a message body. The partial code to create a new mail message is as follows − use ZendMail; $mail = new MailMessage(); $mail->setSubject(”Zend email sample”); $mail->setBody(”This is content of the mail message”); $mail->setFrom(”[email protected]”, “sender-name”); $mail->addTo(”[email protected]”, “recipient-name”); Zend provides ZendMailSendmail class to send the mail message. Sendmail uses the php native mail function, mail to send the mail message and we can configure the transport layer using php configuration file. The partial coding using Sendmail is as follow − $transport = new MailTransportSendmail(); $transport->send($mail); The zend-mail provides many transport layer and each may require many additional parameters such as username, password, etc Email Management Methods Some of the notable email management methods are as follows − isValid − Messages without a ‘From’ address is invalid. isValid() : bool setEncoding − Set the message encoding. setEncoding(string $encoding) : void getEncoding − Get the message encoding. getEncoding() : string setHeaders − Compose headers. setHeaders(ZendMailHeaders $headers) : void getHeaders − Access headers collection. getHeaders() : ZendMailHeaders setFrom − Set (overwrite) From addresses. It contains a key/value pairs where the key is the human readable name and the value is the email address. setFrom( string|AddressInterface|array|AddressList|Traversable $emailOrAddressList, string|null $name ) : void addFrom − Add a ‘From’ address. addFrom( string|AddressInterface|array|AddressList|Traversable $emailOrAddressOrList, string|null $name ) : void getFrom − Retrieve list of ‘From’ senders. getFrom() : AddressList setTo – Overwrite the address list in the To recipients. setTo( string|AddressInterface|array|AddressList|Traversable $emailOrAddressList, null|string $name ) : void setSubject − Set the message subject header value. setSubject(string $subject) :void setBody − Set the message body. setBody(null|string|ZendMimeMessage|object $body) : void SMTP Transport Layer The zend-mail provides options to send an email using the SMTP server through the ZendMailTransportSmtpclass. It is like Sendmail except that it has a few additional options to configure the SMTP host, port, username, password, etc. The partial code is as follows − use ZendMailTransportSmtp as SmtpTransport; use ZendMailTransportSmtpOptions; $transport = new SmtpTransport(); $options = new SmtpOptions([ ”name” => ”localhost”, ”host” =>”smtp.gmail.com”, ”port” => 465, ]); $transport->setOptions($options); Here, name − Name of the SMTP host. host − Remote hostname or IP address. port − Port on which the remote host is listening. Mail Concept – Example Let us follow the following points to write a simple php console application to understand the mail concept. Create a folder “mailapp”. Install zend-mail using the composer tool. Create a php file Mail.php inside the “mailapp” folder. Create the message using the ZendMailMessage. $message = new Message(); $message->addTo(”[email protected]”); $message->addFrom(”[email protected]”); $message->setSubject(”Hello!”); $message->setBody(“My first Zend-mail application!”); Create the SMTP transport layer and add the necessary configuration. // Setup SMTP transport using LOGIN authentication $transport = new SmtpTransport(); $options = new SmtpOptions([ ”name” => ”localhost”, ”host” => ”smtp.gmail.com”, // or any SMTP server ”port” => 465, // port on which the SMTP server is listening ”connection_class” => ”login”, ”connection_config” => [ username” => ”<your username>”, ”password” => ”<your password>”, ”ssl” => ”ssl”], ]); $transport->setOptions($options); Send the email using the send method. $transport->send($message); The complete listing, Mail.php is as follows − <?php require __DIR__ . ”/vendor/autoload.php”; use ZendMailMessage; use ZendMailTransportSmtp as SmtpTransport; use ZendMailTransportSmtpOptions; $message = new Message(); $message->addTo(”[email protected]”); $message->addFrom(”[email protected]”); $message->setSubject(”Hello!”); $message->setBody(“My first Zend-mail application!”); // Setup SMTP transport using LOGIN authentication $transport = new SmtpTransport(); $options = new SmtpOptions([ ”name” => ”localhost”, ”host” => ”smtp.gmail.com”, // or any SMTP server ”port” => 465, // port on which the SMTP server is listening ”connection_class” => ”login”, ”connection_config” => [ ”username” => ”<your username>”, ”password” => ”<your password>”, ”ssl” => ”ssl”], ]); $transport->setOptions($options); $transport->send($message); Now, run the application in the command prompt php Mail.php. This will send the mail as configured in the application. Print Page Previous Next Advertisements ”;

Zend Framework – Error Handling

Zend Framework – Error Handling ”; Previous Next Failure of system needs to be handled effectively for the smooth running of the system. Zend Framework comes with a default error trapping that prints and logs the error as they occur. This same error handler is used to catch Exceptions. The Error Handler displays errors when the debug is true and logs the error when the debug is false. Zend Framework has several exception classes and the built-in exception handling will capture any uncaught exception and render a useful page. Default Error Handling We can configure the default error settings in the application configuration file, myapp/module/Application/config/module.config.php. The partial code sample is as follows − ”view_manager” => [ ”display_not_found_reason” => true, ”display_exceptions” => true, ”doctype” => ”HTML5”, ”not_found_template” => ”error/404”, ”exception_template” => ”error/index”, ”template_map” => [ ”layout/layout” => __DIR__ . ”/../view/layout/layout.phtml”, ”application/index/index” => __DIR__ . ”/../view/application/index/index.phtml”, ”error/404” => __DIR__ . ”/../view/error/404.phtml”, ”error/index” => __DIR__ . ”/../view/error/index.phtml”, ], ”template_path_stack” => [ __DIR__ . ”/../view”, ], ], Here, the display_exception, not_found_template, exception_template, error/404 and the error/index are error related configuration items and are self-explanatory. The most important item among these is the error/index. This is the template shown when an exception occurs in the system. We can modify this template, myapp/module/Application/view/error/index.phtml to control the amount of error to be shown. Print Page Previous Next Advertisements ”;

Zend Framework – Quick Guide

Zend Framework – Quick Guide ”; Previous Next Zend Framework – Introduction A PHP Web Framework is a collection of classes which helps to develop a web application. Zend is one of the most popular PHP framework. It is an open-source MVC framework for rapidly developing, modern web applications. Zend Framework has several loosely coupled components, so it is referred to as “Component Library”. Zend Framework provides any PHP stack and Zend server to run Zend framework applications. Zend Studio is an IDE that includes features to integrate with Zend Framework. It provides MVC view and code generation. The current Zend framework 3.0 includes new components such as JSON RPC server, a XML to JSON converter, PSR-7 functionality, and compatibility with PHP 7. Zend Framework 2 is an open source framework for developing web applications and services using PHP 5.3+. Zend Framework 2 uses 100% object oriented code and utilizes most of the new features of PHP 5.3, namely Namespaces, Lambda Functions and Closures. Zend Framework 2 evolved from Zend Framework 1, a successful PHP framework with over 15 million downloads. Zend Server has a free community version and a commercial version. Zend Framework Features Some of the salient features of Zend Framework is as follows − Pure object oriented web application framework Advanced MVC implementation Supports multi databases including PostgreSQL, SQLite etc., Simple cloud API Session management Data encryption Flexible URI Routing Zend provides RESTful API development support. Code reusable and easier to maintain. Why Zend Framework? What makes the Zend Framework one of the premier frameworks used by PHP developers is that – it provides clean and stable code complete with intellectual property rights. It also makes programming easier. It is fast, easy to learn and convenient framework. Zend supports strong cryptography tools and password hashing techniques. Zend Goals Following are the goals of the Zend Framework. Flexibility Simple and productive Compatibility Extensibility − Programmer can easily extend all the framework classes. Portability − Supports multiple environments Zend Applications The following popular products are developed by using the Zend Framework. McAfee Company website IBM Company website Magento − one of the popular shopping cart website. Advantages of Zend Framework Some of the advantages of the Zend Framework are listed below. Loosely Coupled − Zend provides the option to delete modules or components which we don’t need in the application. Performance − Zend Framework is highly optimized for performance. Zend Framework 3 is 4x faster than its previous version. Security − Framework supports industry standard encryption. Testing − PHPUnit is integrated with Zend so you can easily test the framework. In the next chapter, we will learn how to install the Zend Framework. Zend Framework – Installation To install the Zend Framework, we must first install the Composer and the latest version of PHP as shown in the following steps. Install Composer − Zend uses Composer for managing its dependencies, so make sure you have the Composer installed on your machine. If the Composer is not installed, then visit the official website of Composer and install it. Install the latest version of PHP − To get the maximum benefit of Zend Framework, install the latest version of PHP. The minimum required version for the Zend Framework 3 is PHP 5.6 or later. Install Zend Framework Zend Framework can be installed in two ways. They are as follows − Manual installation Composer based installation Let us discuss both these installations in detail. Manual Installation Download the latest version of Zend Framework by visiting the following link – https://framework.zend.com/downloads/archives Extract the content of the downloaded archive file to the folder you would like to keep it. Once you have a copy of Zend Framework available in your local machine, your Zend Framework based web application can access the framework classes. Though there are several ways to achieve this, your PHP include_path needs to contain the path to the Zend Framework classes under the /library directory in the distribution. This method applies to Zend Framework version 2.4 and earlier only. Composer Based Installation To easily install the Zend Framework, use the Composer tool. This is the preferred method to install the latest version of Zend Framework. To install all the components of the Zend Framework, use the following Composer command − $ composer require zendframework/zendframework Each Zend Framework module / component can be installed individually as well. For example, to install the MVC component of the Zend Framework, use the following composer command − $ composer require zendframework/zend-mvc Zend Framework – Skeleton Application Let us create a skeleton application using the Zend Framework MVC layer and module systems. Installation using Composer The easiest way to create a new Zend Framework project is to use a Composer. It is defined as below − $ cd /path/to/install $ composer create-project -n -sdev zendframework/skeleton-application myapp You would see the following result on your screen − Installing zendframework/skeleton-application (dev-master 941da45b407e4f09e264f000fb537928badb96ed) – Installing zendframework/skeleton-application (dev-master master) Cloning master Created project in myapp Loading composer repositories with package information Installing dependencies (including require-dev) from lock file – Installing zendframework/zend-component-installer (0.3.0) Loading from cache – Installing zendframework/zend-stdlib (3.0.1) Loading from cache – Installing zendframework/zend-config (2.6.0) Loading from cache – Installing zendframework/zend-loader (2.5.1) Loading from cache – Installing zendframework/zend-eventmanager (3.0.1) Loading from cache – Installing zendframework/zend-view (2.8.0) Loading from cache – Installing container-interop/container-interop (1.1.0) Loading from cache – Installing zendframework/zend-servicemanager (3.1.0) Loading from cache – Installing zendframework/zend-validator (2.8.1) Loading from cache – Installing zendframework/zend-escaper (2.5.1) Loading from cache – Installing zendframework/zend-uri (2.5.2) Loading from cache – Installing zendframework/zend-http (2.5.4) Loading from cache – Installing zendframework/zend-router (3.0.2) Loading from cache – Installing zendframework/zend-modulemanager (2.7.2) Loading from cache – Installing zendframework/zend-mvc (3.0.1) Loading from cache – Installing zendframework/zend-skeleton-installer (0.1.3) Loading from cache – Installing zfcampus/zf-development-mode (3.0.0) Loading from cache zendframework/zend-config suggests installing zendframework/zend-filter (ZendFilter component) zendframework/zend-config suggests installing zendframework/zend-i18n (ZendI18n component) zendframework/zend-config suggests installing zendframework/zend-json (ZendJson to use the Json reader or writer classes) zendframework/zend-view suggests installing zendframework/zend-authentication (ZendAuthentication component) zendframework/zend-view suggests installing zendframework/zend-feed (ZendFeed component) zendframework/zend-view suggests

Cookie Management

Zend Framework – Cookie Management ”; Previous Next The Cookie is a very important concept in a web application. It provides the option to persist the user”s data, usually a small piece of information in the browser itself for a limited period. A Cookie is used to maintain the state of the web application. Zend framework provides a cookie module inside the zend-http component. This zend-http provides the HTTP abstraction and its implementation. Installing the HTTP Component The HTTP component can be easily installed using the Composer as specified in the code below. composer require zendframework/zend-http Concept The zend-http provides the ZendHttpCookies class to manage cookies. It is used along with the ZendHttpClient class, which is used to send a request to a web server. Cookies can be initialized as shown in the code below − use ZendHttpCookies $c = new Cookies(); When the HTTP client (ZendHttpClient) first sends a URI request to the web server, it does not have any cookie. Once the request is received by the web server, it includes the cookie in its response object as the HTTP Header, Set-Cookie and sends it to the HTTP client. The HTTP client will extract the cookie from the http response and resent it as same HTTP Header in the subsequent request. Generally, each cookie will be mapped to a domain and a path of the domain. The methods available in Cookies class are as follows − addCookie(uri) − It is used to add a cookie into the request object of the given URI. getCookie(cookieName, $cookieForm) − It is used to get the cookie, $cookieName available in the given URI, $uri. The third argument is how the cookie will be returned, either string or array. fromResponse(uri) − It is used to extract cookies from the response object of the given URI. addCookiesFromResponse − It is same as fromResponse, but it extracts and adds it again into the request object of the given URI. isEmpty() − It is used to find whether the given Cookie object has any cookie or not. reset() − It is used to clear all the cookies in the given URI. In the next chapter, we will discuss regarding session management in the Zend Framework. Print Page Previous Next Advertisements ”;

Zend Framework – Authentication

Zend Framework – Authentication ”; Previous Next Authentication is one of the most significant and must-have feature in any web application. Zend Framework provides a separate component to handle authentication, which is called as the zend-authentication. Install an Authentication Component The authentication component can be installed using the following Composer command. composer require zendframework/zend-authentication Concept Usually, a developer writes a php function to authenticate the user details against a datasource. Once the authentication is done, the authentication details are persisted for subsequent requests. Zend Framework generalizes this concept and provides two classes, which are explained below − Class 1 ZendAuthenticationAdaptorAdaptorInterface This class provides a single method, authenticate to write the authentication logic. The authenticate method returns an instance of ZendAuthenticationResult class. This Result object holds the authentication status; identity if the authentication succeeds and an error message, if the authentication fails. The signature of the authenticate interface and result class is as follows − AdaptorInterface namespace ZendAuthenticationAdaptor; public function authenticate() { // code } Result class namespace ZendAuthentication; class Result { public function __construct($code, $identity, array $messages = []); } The Zend Framework provides a default implementation to authenticate against the database, ldap, http basic and digest credentials. An Adaptor authenticates but does not persist the details for any future requests. Class 2 ZendAuthenticationAuthenticationService The AuthenticationService is the main component, which uses the already configured adaptor for authentication purposes. Once the authentication is done, it persists the authentication details and provides methods, hasIdentity() to check whether an identity is available, getIdentity() to get the authentication details and clearIdentity() to clear the authentication details. The partial code listing to use this AuthenticationService is as follows − $adap = new Adapter($username, $password); $auth = new AuthenticationService(); $result = $auth->authenticate($adap); if($result->isValid) { $identity = $auth->getIdentity(); } else { // process $result->getMessages() } // clear $auth->clearIdentity(); The stuff related to authorization are packaged as two separate modules, which are – zend-permissions-acl and zend-permissions-rbac. The zend-permissions-acl is based on the Access control list and the zend-permissions-rbac is based on the role based access control list. They provide high-level abstraction of ACL & RBAC concept and aids in writing the enterprise grade application. Print Page Previous Next Advertisements ”;

Session Management

Zend Framework – Session Management ”; Previous Next A Session is a very important concept in a web application. It provides the option to persist the user”s data in the web server for a limited period of time. Zend framework provides a separate component, zend-session to handle the session information. Install a Session Component Session component can be installed using the Composer as specified below − composer require zendframework/zend-session Session Components Zend framework provides six components to handle session management. All these components have been explained below − ZendSessionContainer − The main API to read and write the session information. ZendSessionSessionManager − It is used to manage the entire lifecycle of a session. ZendSessionStorage − This is used to specify how the session data will be stored in the memory. ZendSessionSaveHandler − It is used to store and retrieve the session data into a physical location like RDBMS, Redis, MangoDB, etc. ZendSessionValidator − This is used to protect session from hijacking by cross-checking initial and subsequent request”s remote address and user agent. ZendSessionConfigSessionConfig − It is used to configure how the session should behave. The default configuration is enough to work with a session. Using the above components, all aspects of a session can be handled easily. Session Component Example Let us adhere to the following points to create a new page to understand a session in Zend framework. By default, it is enough to create an instance of a Container class to manage sessions. Create a new action, sessionAction in TutorialController. Initialize a Container object. $c = new Container(); Check whether an arbitrary key count exists. If the key is not available, initialize the count with value 1. If it is available, increment the value as shown in the following code. if (!isset($c->count)) { $c->count = 0; } else { $c->count++; } Register the count in the ViewModel. Create a template file for – sessionAction, session.phtml in myapp/module/Tutorial/view/tutorial/tutorial/session.phtml and then render the count value. Refreshing the page will increase the value of count in the session. The complete listing is as follows − TutorialController.php public function sessionAction() { $c = new Container(); if (!isset($c->count)) { $c->count = 0; } else { $c->count++; } $view = new ViewModel([ ”count” => $c->count, ]); return $view; } session.pthml Session data, COUNT = <?= $this->count ?> Sample Result Session data, Count = 5 Print Page Previous Next Advertisements ”;

Zend Framework – Concepts

Zend Framework – Concepts ”; Previous Next Zend Framework is a collection of 60+ components. They are loosely connected with each other. They can be used as both stand-alone component as well as a group of components working as a single unit. Zend Framework provides three most important components, which are − zend-servicemanager zend-eventmanager and zend-modulemanager. They provide Zend components the ability to integrate with other components efficiently. Event Manager − It gives the ability to create event based programming. This helps to create, inject and manage new events. Service Manager − It gives the ability to consume any services (PHP classes) from anywhere with a little effort. Module Manager − Ability to convert a collection of PHP classes with similar functionality into a single unit called as a module. The newly created modules can be used, maintained and configured as a single unit. We will cover these concepts in detail in the subsequent chapters. Print Page Previous Next Advertisements ”;