Thursday, April 12, 2007

How Much Is Portable Hot Tub?

Zend Framework - Database Applications


admit frankly that I came to the Zend Framework with practices at IBM, where he came to me to test a hybrid data engine (pureXML in DB2 9). I decided to play because the server Zend Core for IBM (fairly quickly switched to Zend Core 2) and at his installation ZF noticed.
In the era of object-oriented programming we have a wide range of APIs, which we record zdeserializują array to an object class, allow it to easily modify and re-serialization. A prime example is at the moment probably the Java Persistence API is described in detail by Jacek Laskowski , but of course such a possibility in the Zend Framework could not miss.
therefore decided to discuss the mechanism and draw attention to an important issue in my view - to avoid deserialization of objects and use arrays or associative arrays there (in Java it would use a collection or array built-in types), where it is important to efficient processing of information.


In my example I will use the table that describes a bunch of cosmic rays, similar to the one I work every day:
 
CREATE TABLE cosmic_rays (
id serial NOT NULL, - Automatically generated identifier
nix_date float8, - Unix ' The new timestamp
peak_particles float 8, - The number of registered particles
az float4, - The source of the coordinates of the horizontal - the azimuth
float4, - The source of horizontal coordinates - the distance from the zenith
ra float4, - The source of the coordinates of the blue - dec rekt Mother Ascensión
float4, - The source of the coordinates of the blue - declination
l float4, - The sources in the galactic coordinates - the width of gal
b float4, - The sources in the galactic coordinates - the length of gal
CONSTRAINT id PRIMARY KEY (id)
) WITHOUT Oids;

As you might guess the table is prepared for the base based on PostgreSQL, but do not need multiple treatments in order to adapt it to another database system.


in the project directory structure


As in the previous example based on Zend Framework structure will look as follows:


  • application

    • controllers

      • IndexController.php


    • models

      • CosmicRays.php


    • views


  • configuration

    • config.xml


  • library

    • Zend

    • Zend.php


  • public

  • . Htaccess index.php




File . htaccess file also contains only control information for the rewrite module:
 
RewriteEngine on RewriteRule .* index.php




Initializing database connection


config.xml file will contain the necessary to compile a database connection information:
 
\u0026lt;? xml version = "1.0" encoding = "utf-8">
\u0026lt;configData>
\u0026lt;db>
\u0026lt;adapter> PDO_Pgsql \u0026lt;/ adapter>
\u0026lt;configuration>
\u0026lt;host> localhost \u0026lt;/ host>
\u0026lt;port> 5432 \u0026lt;/ port>
\u0026lt;dbname> Database \u0026lt;/ dbname>
\u0026lt;username> user \u0026lt;/ username>
\u0026lt;password> *****\u0026lt;/ password>
\u0026lt;/ configuration>
\u0026lt;/ db>
\u0026lt;/ configData>

We can then proceed to configure the bootstrap index.php file:
 
/ / Set the path
set_include_path ('..' PATH_SEPARATOR
. '. / library'. PATH_SEPARATOR
. '. / application / models /'. PATH_SEPARATOR
. get_include_path ());

/ / Load the class require_once Zend_Loader
'Zend / Loader.php';



try {/ / Load the necessary classes
Zend_Loader:: loadClass ('Zend_Config_Xml');
Zend_Loader:: loadClass ('Zend_Db');
Zend_Loader:: loadClass ('Zend_Db_Table');

Zend_Loader:: loadClass ('Zend_Registry');
Zend_Loader:: loadClass ('Zend_View');
Zend_Loader:: loadClass ('Zend_Controller_Front');

/ / We set the base address
$ baseurl = substr ($ _SERVER ['PHP_SELF'], 0 ,
strpos ($ _SERVER ['PHP_SELF'], '/ index.php'));

/ / Load the configuration database file XML (db branch)
$ config = new Zend_Config_Xml ('. / Configuration / config.xml', 'db');

/ / Create a connection to the database and making it the default for models
tables $ db = Zend_Db: factory ($ config-> adapter,
$ config-> configuration-> asArray ());
Zend_Db_Table:: setDefaultAdapter ($ db);


/ / Configure class
view $ view = new Zend_View ();
$ view-> baseurl = $ baseurl;
$ view-> setScriptPath ('. / application / views');
/ / Place it in the registry
Zend_Registry:: set ('view', $ view);

/ / Initialize the main controller
$ FrontController = Zend_Controller_Front:: getInstance ();
$ FrontController-> setRouter ($ router);
$ FrontController-> setBaseUrl ($ baseurl);
$ FrontController-> setControllerDirectory (
'. / application / controllers');
$ FrontController-> throwExceptions (true);
$ FrontController-> returnResponse (true);

/ / Initialize the response object $ response
= $ FrontController-> dispatch ();
$ response-> renderExceptions (true);
$ response-> setHeader ('Pragma', 'no-cache');
$ response-> setHeader ('Cache-Control', 'no-cache');

/ / Display the
echo $ response;

} catch (Exception $ e) {
/ / Exception handling
die ($ e-> getMessage ());}


As can be seen adding support to our data base required us to 6 lines of code (including the import of the relevant files libraries). It
Zend_Config_Xml (inheriting Zend_Config) is an object that allows for easy loading of configuration files in the form of XML documents. Its use is very similar to handling XML files using SimpleXML (see earlier post).
Initialization make calls through a static factory method Zend_Db class, where we serve the type of adapter (for most databases are PDO adapters, adapters have only their own DB2, Oracle, and MySQLi), and configuration parameters.
The static method of class setDefaultAdapter Zend_Db_Table set to link to all the objects associated with tables.


Our first model


CosmicRays.php In the file put, our model for the table cosmic_rays:
 
Zend_Loader:: loadClass ('Zend_Db_Table');

CosmicRays class extends Zend_Db_Table {
_setup protected function () {
/ / standard ZF set the table name as a string representing
/ / _ after the last character in the name of the class model, so we change it
$ this-> _name = 'cosmic_rays';
/ / We can also set your primary key (if other than d)
/ / and the schema of the table (especially important for databases such as DB2 or Oracle)

/ / On Finally we load the base class setting
parent:: _setup ();}

}

And it would be enough. We just have to create an object of class CosmicRays and we can modify the objects. There we have the method (I mentioned the most important):

  • fetchNew () - creates a new empty "record"

  • fetchRow ($ where, $ order) - returns the first "record" with the result satisfies the condition $ where $ order of the rearrangement

  • fetchAll ($ where, $ order) - returns all the "records"

  • insert ($ data) - inserts a "record" on the basis of an associative array

  • update ($ data, $ Where) - updates the data based on an associative array


worth noting that the method returns the object fetchAll Zend_Db_Table_Rowset type of iterator for objects Zend_Db_Table_Rows (so you can browse the collection using a foreach loop). FetchNew fetchRow methods and return to us an object of type Zend_Db_Table_Row. Each object
Zend_Db_Table_Row available to us in a manner similar to the objects stClass. Therefore, we can modify them easily (it is not acceptable merely modified primary key), for example
 
$ mp = new CosmicRays ();
$ row = $ cr-> fetchRow ('id = 10 ");
$ row-> ra = 0;
$ row-> update ();

quoted above, the method update () gives us the opportunity to update the object. You can also save () method allows you to record a new object created using the method fetchNew ().


performance problem


problem for which I found was to download only two columns from the entire table. Of course, we can create an object select. However, this requires the placement of the object $ db in the registry, or wyłuskania from the object model.
course for queries joining data from multiple table is practically the only method. But what if we want the shell with only one table? Let

new method in the model class:
 
public function fetchAllColumns ( $ columns = null , $ where = null, $ order = null, $
count = null, $ offset = null) {

/ / selection
tool $ select = $ this-> _db-> select ();

/ / Set columns
$ columns = (is_null ($ columns))? $ this-> _cols: $ columns;


/ / the FROM clause $ select
-> from ($ this-> _name, $columns);

// the WHERE clause
$where = (array) $where;
foreach ($where as $key => $val) {
// is $key an int?
if (is_int($key)) {
// $val is the full condition
$select->where($val);
} else {
// $key is the condition with placeholder,
// and $val is quoted into the condition
$select->where($key, $val);
}
}

// the ORDER clause
if (!is_array($order)) {
$order = array ($ order);}

foreach ($ order as $ val) {$
select-> order ($ val);}


/ / the LIMIT clause $ select
-> limit ($ count, $ offset );

/ / return the results $ stmt
= $ this-> _db-> query ($ select);
$ data = $ stmt-> fetchAll (Zend_Db: FETCH_ASSOC);

return $ data;}


Those who watched the class Zend_Db_Table_Abstract quickly notice that my method is not nothing but a slightly modified method _fetch (...).
is worth a look at the implementations fetchAll (...) method of this class. Well, an associative array, it wraps in a Zend_Db_Table_Rowset. In situations where we want efficiency and low demand for memory should refrain from facilitating the class entails Zend_Db_Table_Rowset.

At the end of yet another council. Feel free to use the user unset ($ data), especially if the object $ data array is large in size, which still does not intend to use. Especially because the server administrators often do not provide for the php scripts more than 16MB of memory.

Wednesday, April 4, 2007

Blogs De Putas Famosas Mexicanas

XML Processing in Java and PHP (Part 2)


For PHP XML support accessibility standards evolved, along with subsequent versions. For version 3 was available SAX interface, which has not changed up to now (compatibility issues may be related only to support the namespace for the elements, if you have the libxml2 library earlier than version 2.6).


In Version 4 added support for DOM (domxml extension) and XSLT (xslt extension). The first of these, however, did not meet the W3C guidelines, resulted in a lot of memory leaks, which was not too popular. The second requires the Sablotron library activities or Expat.


breakthrough resulted in version 5 Support for DOM has been rewritten, in accordance with the standards and placed in the W3C DOM extension. Added support for XPath and DTD validation according to the file (the link contained in a XML file), XSchema and RelaxNG (file name defined in the function call).
was based on XSLT libxslt library (the fastest on the market) and placed in the XSL extension. Both also gained
truly object-oriented nature. Moreover
added SimpleXML interface for easy modification of XML file without a significant burden system characteristic of the DOM.


SAX


SAX parser by calling the create xml_parser_create (); The next step is to create functions corresponding to the XML events and registering them. At http://pl.php.net/manual/en/ref.xml.php # id7330424 available example of such a parser (including the verification of external entities.)


DOM and SimpleXML


For PHP 5 using the DOM is the same as in other programming languages \u200b\u200b(JavaScript, Java, ...). Work with him start by creating a DOMDocument object. SimpleXML
other hand, is a very interesting intefejsem. Based on the XML file it creates something like a PHP class stdClass (for other object-oriented languages, you can compare it to the class which is a collection of objects). Thanks to that refer to an element in a very pleasant way (Zend intefejs used this to create Zend_Config_Xml).
worth noting that, by function and dom_import_simplexml simplexml_import_dom can easily convert data from one standard to another (this is particularly useful for saving the XML document to a file, which is a SimpleXML function does not).


Example


Finally, I present an example that retrieves data from the Customers table (the base Sample XML for IBM DB2 9) and draw from them the name of the client. I want to draw attention to two elements. First, differences in the volume of SimpleXML and DOM performing the same operation. Secondly, it is worth noting that the methods of class DOMDocument in PHP and Java Document for the same:
 
error_reporting (E_ALL
$port = 50000;

$connect_string = "DRIVER={IBM DB2 ODBC DRIVER};" .
"DATABASE=$database;" .
"HOSTNAME=$hostname;" .
"PORT=$port;" .
"PROTOCOL=TCPIP;" .
"UID=$user;" .
"PWD=$password;";
$connection = db2_connect($connect_string,'','');
if ($connection){
echo "Connection successful.<br />";
$sql = "SELECT INFO FROM CUSTOMER WHERE CID = ?";
$statement = db2_prepare($connection, $sql);
db2_execute($statement,array(1001));

while ($customer = db2_fetch_object($statement)){
$info = $customer->INFO;

//SimpleXML
$simpleXML = new SimpleXMLElement($info);
echo $simpleXML->name."<br />";

//DOM
$domDocument = new DOMDocument('1.0','UTF-8');
$domDocument->loadXML($info);
$names = $domDocument->getElementsByTagName('name');
foreach ($names as $name) {
echo $name->nodeValue.'<br /> ';}

}
db2_close ($ connection);

} else {echo "Connection failed."}






Summary


shown in both examples represent only tip of the iceberg relating to the processing of XML documents in Java and PHP. However, I can be a useful prelude to further exploration.
All kinds of comments and suggestions are welcome



Gay Cruising Pasco County

Processing XML in Java and PHP (Part 1)


implementing practices from IBM's DB2 9 database (in particular its hybrid engine) encountered a lack of information on the processing of XML data available in the form of streams.
After searching the internet I came across the Streaming API for XML (STAX) and its documentation in the form of JSR-173. It turned out that Java SE 1.6 interface provides up to him, but there is no implementation. On the
http://stax.codehaus.org/
quickly found that implementation, then I came across yet to implement Sun's (
at https: / / sjsxp.dev.java.net /
) and Bea Weblogic (at
http://dev2dev.bea.com/xml/stax.html ). Since the first of these three is the reference implementation will be used in this tutorial. Regardless of everything I decided to once again check the text stream analysis capabilities with XML for standards Simple API for XML (SAX) and Document Object Model (DOM). It turned out that was stuck in the mistaken belief.




SAX


SAX is considered the fastest and least memory-XML parser. Based on the representation of event-driven, where the opening and closing of each document, a marker of the presence of the text is defined as an event.
Saxa undoubted disadvantage is lack of knowledge about the location of the XML file (the state). It is also quite hard to implement projects in their own interface.

Work with SAXem start by creating a class of reacting to events (for me MyHandler). The following example is based on the code contained in the book J2EE. Vademecum Developer commercially available Helion SA:


package org.f2k.test;


import java.io.IOException;
 import java.io.OutputStreamWriter; 
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class MyHandler extends DefaultHandler {
StringBuffer textBuffer;
static private Writer out;

public MyHandler() throws UnsupportedEncodingException{
out = new OutputStreamWriter(System.out, "UTF8");
}

public void startDocument() throws SAXException{
nl();
nl ();
emit ("START OF DOCUMENT");
nl ();
emit ("
");


} public void endDocument () throws SAXException {
nl (); emit ("END OF DOCUMENT ");

try {nl ();
out.flush ();
} catch (IOException e) {throw new SAXException
(" IO Exception ", e);}


} public void startElement
( String namespaceURI, String
sname, / / \u200b\u200bshort name
String qname, / / \u200b\u200bfull name
Attributes attrs) throws SAXException {

echoText ();
nl ();
emit ("ELEMENT:");
Enam String sname = / / element name
/ / without taking into account the namespace name
if ("". equals (Enam))
Enam = QName;
emit ("
if (attrs! = null) {
for (int i = 0; and
anama String = attrs.getLocalName (i) / / attribute name
if (" ". equals (Maanam)) anama = attrs.getQName (i);
nl (); <"+eName);
emit ("ATR:");
emit (Maanam); < attrs.getLength(); i++) {
emit ("\\ t \\" ");
emit (attrs.getValue (i)) ;
emit ("\\" ");}


} if (attrs.getLength ()> 0) nl ();
emit (">");


} public void endElement (String namespaceURI, String sname
/ / short name
String qname / /
full name) throws SAXException {
echoText ();
nl ();
emit ("END_OF_ELEM:");
Enam String sname = / / element name
if (" ". equals (Enam))
Enam = qname;
emit ("
");}


public void characters (char buf [], int offset, int len)
throws SAXException{ String s = new String(buf, offset, len);
if (textBuffer == null) {
textBuffer = new StringBuffer(s);
} else {
textBuffer.append(s);
}
}


// Metody pomocnicze
private void echoText() throws SAXException{
if (textBuffer == null) return;
nl();
emit("CHARS: throws SAXException {try {

out.write (s);
out.flush ();
} catch (IOException e) {throw new SAXException
("IO Exception", e);

}} private void

nl () throws SAXException {String
lineEnd = System.getProperty ("line.separator");

try {out.write (lineEnd);
} catch (IOException e) {throw new SAXException
("IO Exception", e);

}}}



We have a class that supports the event get ready class of a test by which we can provide the String containing XML


org.f2k.test package;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
javax.xml.parsers.SAXParser import, import
javax.xml. parsers.SAXParserFactory;
import org.xml.sax.helpers.DefaultHandler;
SAXTest {public class
SAXTest (String xml) {
this (new ByteArrayInputStream (xml.getBytes
 ()));} 

SAXTest (InputStream stream) {try {

DefaultHandler handler = new MyHandler ();
SAXParserFactory SAXParserFactory.newInstance factory = ();
SAXParser parser = factory.newSAXParser ();
parser.parse (stream, handler);
} catch (Exception e) {e.printStackTrace
();

}}}



We have virtually everything you need for SAX. We can still set for the object factory option to check an XML document by the DTD, etc. But the longer I leave it to developers:)





HOUSE




DOM parser is that the complex is used to modify the XML, or its representation in a tree object. Its disadvantage is that it is zasobożerny. The entire document is in fact processed in memory computer.

In the case of DOM, we can immediately write our test class: package

org.f2k.test; import java.io.ByteArrayInputStream; import java.io.InputStream;
javax.xml.parsers.DocumentBuilder import;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;

DOMTest public class {public
DOMTest (String xml) {
 this (new ByteArrayInputStream ( xml.getBytes 
()));} public

DOMTest (InputStream stream) {try {

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance ();
DocumentBuilder builder = factory.newDocumentBuilder ();
Document document = builder.parse (stream);
NodeList names = document.getElementsByTagName ("name");
for (int i = 0; i \u0026lt;names.getLength () , i + +) {System.out.println
(names.item (i). getTextContent ());

}} catch (Exception e) {e.printStackTrace
();

}}}

Our

test looks for nodes in an XML document called name and displays their contents.





STAX




pareserem STAX is developed by BEA. Although his action is based on event-driven XML form, it gives us the knowledge of the position in the document through the iterator. This allows for faster than the DOM deserializację simple objects.


STAX easiest to use is to create a function that will analyze the incident. The following example will implement the processEvent function similar task to the class of test MyHandler SAX:
org.f2k.test package; import java.io. *;
javax.xml.stream import .*;
import javax.xml . stream.events .*;


public class StAXTest {
StringBuffer textBuffer;
static private Writer out;
    StAXTest(String xml){ 
this(new ByteArrayInputStream(xml.getBytes()));
}

StAXTest(InputStream stream){
try {
out = new OutputStreamWriter(System.out, "UTF8");
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
/*Implementation of StAX*/
System.setProperty("javax.xml.stream.XMLInputFactory",
"com.bea.xml.stream.MXParserFactory");

try {
XMLInputFactory inputFactory
= XMLInputFactory.newInstance();
XMLEventReader eventReader
= inputFactory.createXMLEventReader(stream);
while (eventReader.hasNext()){
XMLEvent event = (XMLEvent) eventReader.next();
processEvent(event);
}
} catch (Exception e) {
e.printStackTrace();
}
}

public void processEvent(XMLEvent event) throws IOException{
if (event.isStartElement()){
echoText();
nl();
emit("ELEMENT:
emit(((StartElement) event).getName().toString());
emit(">");
}
if (event.isCharacters()){
String s = ((Characters) event).getData();
if (textBuffer==null){
textBuffer = new StringBuffer(s);
} else {
textBuffer.append(s);
}
}
if (event.isEndElement()){ <");
echoText();
nl();
emit("END_OF_ELEM: ";
emit("
");
}
}

// Metody pomocnicze
private void echoText() throws IOException{
if (textBuffer == null) return;
nl ();
emit ("Chars: DB2 9th Below the code that gets the call and collate records:


org.f2k.test package;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement ;
import java.sql.ResultSet;
import com.ibm.db2.jcc.DB2Xml;

DB2Connector public class String {
="***";
password String user = "db2admin";

String url = "jdbc: db2: / / localhost: 50000/SAMPLE" public
DB2Connector () {try {

Class.forName ("com.ibm.db2.jcc.DB2Driver"). newInstance ();
Connection conn = DriverManager.getConnection (url,
user, password);
PreparedStatement stmt = conn.prepareStatement (
"SELECT INFO FROM MCUSTOMER WHERE CID =?");
/ / should check whether the user of the CID in 1001, there
stmt. SETINT (1, 1001);
ResultSet result = stmt.executeQuery ();
while (result.next ()) {
DB2Xml info = (DB2Xml) result.getObject ("INFO");
xmlText String = info.getDB2XmlString ();
System.out.println ("DB2XmlString: \\ n" + xmlText);
 / / For Encoding other than UTF-8 passes the test only STAX 
InputStream stream = info.getDB2XmlBinaryStream ("UTF-8");
System.out.println ("\\ n");
System.out.println ("DB2Xml from STAX test: ");
new StAXTest (stream);
System.out.println (" \\ n ");
System.out.println (" SAX DB2Xml from test ");
stream.reset ();
new SAXTest ( stream);
System.out.println ("\\ n");
System.out.println ("DOM DB2Xml from test");
stream.reset ();
new DOMTest (stream);}

result.close ();
conn.Close ();
} catch (Exception e) {e.printStackTrace
();}



} public static void main (String [] args) {new DB2Connector
() ;

}}







Results





STAX parser and SAX should pay as a result of shredded XML structure with descriptions of events. However, DOM should display the name of the client learned from XML (for me Kathy Smith.)



The second part will describe the processing systems XML with PHP. Also, based on data taken from DB2.




Vidio Lesbian Milena Velba

Zend_Controller_Router_Route and creating new routes (for version 0.9 and later)



Wojciech As rightly pointed out in the commentary to the previous post since version 0.9 was introduced a few changes. Among other things, to place the library in one directory, it was decided to divide the class into several other Zend. File Zend.php Provides disappear in version 1.0.

Since I'm in your project was based on version 0.8 I decided to give a modified version of the code, and in fact only part of the index.php file:


/ / From now on, instead of loading a class file loader Zend.php
require_once 'Zend / Loader.php ';


try {/ / Load classes done by the method of the class

/ /
Zend_Loader


/ /
In addition, service class is required for register

Zend_Loader:: loadClass ('Zend_Registry');
Zend_Loader:: loadClass ('Zend_Controller_Front');

Zend_Loader:: loadClass ('Zend_Controller_Router_Rewrite');

/ / We set the base address
 $ baseurl = substr ($ _SERVER ['PHP_SELF'], 0, 

strpos ($ _SERVER ['PHP_SELF'], '/ Index.php'));

/ / Configure class
view $ view = new Zend_View ();
$ view-> baseurl = $ baseurl;
$ view-> setScriptPath ('. / Application / views') ;
/ / Place it in the registry by the device of a new class Zend_Registry:: set ('view', $ view);

rest of the code remains unchanged


Tuesday, April 3, 2007

Does A Chest Infection Affect Fetus

Zend_Controller_Router_Route and creating new routes



recently on the Polish forum for Zend Framework I met with the problem of clean URLs. This library supports the standard addresses of the form:


http://nazwa_strony/nazwa_kontrolera/nazwa_akcji/parametr/wartość However


page was to contain a multi-lingual content. And although Zend supports the ability to read information from the browser developer is wanted to control the tongue by placing the code before the name of the controller, for example:


http://nazwa_strony/pl/nazwa_kontrolera/ ...


therefore decided to consult the documentation and write the necessary code. We'll start with the directory structure, which is taken from a tutorial:




application

controllers


IndexController.php
models


views

library


Zend

Zend.php

    public
    • . htaccess index.php

      file. htaccess contains control information for the module rewrite :

    • RewriteEngine on RewriteRule .* index.php

    index.php file is the so-called bootstrap for ZF. In it we make must initialize all the elements necessary for the operation environment. And so to work:

  • / / Set debug
    • define ('_DEBUG', 1);

    • if (defined ('_DEBUG'))
    if (_DEBUG == 1)

  • error_reporting (E_ALL

  • try {/ / Load the necessary classes
  • Zend:: loadClass ('Zend_View');

Zend:: loadClass ('Zend_Controller_Front');

Zend:: loadClass ('Zend_Controller_Router_Rewrite');

/ / Set the base address

$ baseurl = substr ($ _SERVER ['PHP_SELF'], 0,
 strpos ($ _SERVER ['PHP_SELF'], '/ index.php')); 



/ / Configuration class
view $ view = new Zend_View ();

$ view-> baseurl = $ baseurl;

$ view-> setScriptPath ('. / Application / views');

Zend:: register ('view', $ view);



/ / Here we configure the new route

$ route = new Zend_Controller_Router_Route (

': lang /: controller /: action',

/ / Defines
language in front of the controller


array ('lang' => 'en', 'controller' => 'index',

'action' => 'index'), / / \u200b\u200bdefault values \u200b\u200b

array ('lang'=>'[ a-z_ ]+')); / / Condition for lang



/ / Create a router to route our

$ router = new Zend_Controller_Router_Rewrite ();

$ router-> removeDefaultRoutes ();

$ router-> addRoute ('user', $ route );



/ / Initialize the main controller

$ FrontController = Zend_Controller_Front:: getInstance ();

$ FrontController-> setRouter ($ router);

$ FrontController-> setBaseUrl ($ baseurl);
$
FrontController-> setControllerDirectory (

'. / Application / controllers');

$ FrontController-> throwExceptions (true);

$ FrontController-> returnResponse (true);



/ / Initialize the response object

$ response = $ FrontController-> dispatch ();

$ response-> renderExceptions (true);

$ response-> setHeader ('Pragma', 'no-cache');

$ response-> setHeader ('Cache-Control', 'no- cache ');



/ / Display the
echo $ response;} catch
(Exception $ exception) {

/ / Operation of exception

$ message = 'setup
Application exception:
';

$ message .= $ exception-> getMessage ();

if (defined ('_DEBUG') ) if (_DEBUG) {

$ message .= '
Trace:
'. $ exception-> getTraceAsString ();}



die ($ message);}




There remains therefore nothing but learn about the language. This is done in the file IndexController.php:


class IndexController extends Zend_Controller_Action

{

indexAction function () {



echo $ this-> _getParam ('lang', 'en');

echo "in IndexController: indexAction ();}



}


When copying files to the server will get information about the language and developed a method





Daughter Didn't Invite Me To Her Wedding

Greeting


At the outset I do not quite welcome all those who appeared on my blog. It was formed properly under the influence of Jack Laskowski, who clearly shares his experiences from the J2EE. Although
I can not compare their knowledge of the scope of a Jack. However, I decided to share their experiences with the programming. Often touching to me to be technologies that were not popular on the Polish market, and it was hard to find a detailed description of their actions.
I invite you to read and comment on my new posts.