background preloader

Php

Facebook Twitter

The Front Controller. Overview Zend_Controller_Front implements a » Front Controller pattern used in » Model-View-Controller (MVC) applications. Its purpose is to initialize the request environment, route the incoming request, and then dispatch any discovered actions; it aggregates any responses and returns them when the process is complete.

Zend_Controller_Front also implements the » Singleton pattern, meaning only a single instance of it may be available at any given time. This allows it to also act as a registry on which the other objects in the dispatch process may draw. Zend_Controller_Front registers a plugin broker with itself, allowing various events it triggers to be observed by plugins. In most cases, this gives the developer the opportunity to tailor the dispatch process to the site without the need to extend the front controller to add functionality. At a bare minimum, the front controller needs one or more paths to directories containing action controllers in order to do its work. Primary Methods. Zend Framework Manual.

Variable handling Functions. Object Interfaces. I was wondering if implementing interfaces will take into account inheritance. That is, can inherited methods be used to follow an interface's structure? <? Php interface Auxiliary_Platform { public function Weapon(); public function Health(); public function Shields(); } class T806 extends T805 implements Auxiliary_Platform { public function Weapon() { var_dump(__CLASS__); } public function Shields() { var_dump(__CLASS__ . "->" . __FUNCTION__); } } $T805 = new T805();$T805->Weapon();$T805->Health();$T805->Shields(); echo "<hr />"; $T806 = new T806();$T806->Weapon();$T806->Health();$T806->Shields(); ? If the code were to be the same, but instead T805 (or T806) DOES NOT implement Auxiliary_Platform, then it'll still work.

This seems to work in PHP5.2.9-2, PHP5.3 and PHP5.3.1 (my current versions). We could also do the opposite: class T805 { public function Weapon() { var_dump(__CLASS__); } } $T805 = new T805();$T805->Weapon(); Debugging techniques for PHP programmers. Introduction There are many PHP debugging techniques that can save you countless hours when coding. An effective but basic debugging technique is to simply turn on error reporting.

Another slightly more advanced technique involves using print statements, which can help pinpoint more elusive bugs by displaying what is actually going onto the screen. PHPeclipse is an Eclipse plug-in that can highlight common syntax errors and can be used in conjunction with a debugger to set breakpoints. Setting up To learn the concepts described in this article, you are going to need PHP, a Web server, and Eclipse. We need a Web server to parse the pages you create in PHP and display them to the browser. To take advantage of some of the debugging techniques in this article, you need to install Eclipse V3.1.1 and the plug-in: PHPeclipse V1.1.8. You also need the debugger module extension for PHP. See Resources for download information.

Back to top Error messages Error reporting in PHP Testing error reporting <? Variable variables. Sometimes it is convenient to be able to have variable variable names. That is, a variable name which can be set and used dynamically. A normal variable is set with a statement such as: A variable variable takes the value of a variable and treats that as the name of a variable. In the above example, hello, can be used as the name of a variable by using two dollar signs. i.e.

At this point two variables have been defined and stored in the PHP symbol tree: with contents "hello" and with contents "world". Therefore, this statement: produces the exact same output as: i.e. they both produce: hello world. In order to use variable variables with arrays, you have to resolve an ambiguity problem. Class properties may also be accessed using variable property names.

Curly braces may also be used, to clearly delimit the property name. Example #1 Variable property example <? $foo = new foo();$bar = 'bar';$baz = array('foo', 'bar', 'baz', 'quux');echo $foo->$bar . $arr = 'arr';echo $foo->$arr[1] . Warning. Login example with Zend_Auth ~ Robert Basic. Happy New Year! Hope everyone had a blast for New Year's Eve and managed to get some rest :) This is my first working day for this year. I'm still kinda lazy and sleepy.

And I wanna eat something all the time. Damn you candies!!! So, here's what I'm going to do: authenticate an user against a database table using Zend Framework's Zend_Auth component. Preparation Because I'm gonna use a database, be sure to have set the default database adapter in the bootstrap file, I have it setup like this: $config = new Zend_Config_Ini('.. $config = new Zend_Config_Ini('.. I'll need it later in the code. -- -- Table structure for table `zendLogin` -- CREATE TABLE `zendLogin` ( `id` int(11) NOT NULL auto_increment, `username` varchar(32) NOT NULL, `password` varchar(32) NOT NULL, `name` varchar(100) NOT NULL, `email` varchar(100) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ; The login controller The magic happens in the LoginController. // is the user a valid one?

Login and Authentication with Zend Framework - phly, boy, phly. Login and Authentication with Zend Framework Update: this article is now available in French, courtesy of Frédéric Blanc. I've fielded a number of questions from people wanting to know how to handle authentication and identity persistence in Zend Framework. The typical issue is that they're unsure how to combine: An authentication adapter A login form A controller for login/logout actions Checking for an authenticated user in subsequent requests It's not terribly difficult, but it does require knowing how the various pieces of the MVC fit together, and how to use Zend_Auth.

Authentication Adapter For all this to work, you'll need an authentication adapter. Our login controller will make use of the adapter, but simply have a placeholder for retrieving it. Login Form The login form itself is pretty simple. Username must be alphabetic characters only, and must contain between 3 and 20 characters Password must consist of alphanumeric characters only, and must be between 6 and 20 characters <? ZUI - Zoomable User Interface. Jeff Raskin's Humane Interface, the fabled ZUI, is nearly here. Whether zooming forward and back above a desktop will be tedium or if it's more efficient than a conventional GUI is yet to be seen - I think it would feel more coherent than a WIMP GUI, though. As I understand it, zoomable desktops aren't a significant change. You have the same widgets (scrollbars, drop-down menus, tickboxes) but there aren't windows. A WIMP (left) limits the viewable document to the size of the window it's contained within.

Modern file managers such as Nautilus use the contents of a file as the icon. "You just zoom in, and as soon as you can read the text or see the graphic details, you can work on them. From a distant view of several icons you zoom in; the icon takes up your whole screen and you can see the contents of the file; select a line and begin typing; zoom back out (the file is saved as you zoom out - earlier versions can be reverted to).

A ZUI isn't really a 3D interface (two and a half?) Introduction. Zend_Auth provides an API for authentication and includes concrete authentication adapters for common use case scenarios. Zend_Auth is concerned only with authentication and not with authorization. Authentication is loosely defined as determining whether an entity actually is what it purports to be (i.e., identification), based on some set of credentials. Authorization, the process of deciding whether to allow an entity access to, or to perform operations upon, other entities is outside the scope of Zend_Auth. For more information about authorization and access control with Zend Framework, please see Zend_Acl.

Note: The Zend_Auth class implements the Singleton pattern - only one instance of the class is available - through its static getInstance() method. This means that using the new operator and the clone keyword will not work with the Zend_Auth class; use Zend_Auth::getInstance() instead. Adapters Each Zend_Auth adapter class implements Zend_Auth_Adapter_Interface. Results Usage. PHP Tutorial: Writing Your First PHP Script: A Feedback Form (a FormMail Script) Getting Started with PHP: Write a FormMail Script in PHP by Christopher Heng, thesitewizard.com I have always believed that the most fun way to learn a new programming language, whether it is a language like C or a scripting language like PHP, is to use it to write a real-life useful program.

Of course this is not the most systematic method of learning, but it works well if you already have some background in programming. Preliminaries Before you write your first PHP program, make sure that your website is running on a web host that runs PHP 4.1 or above. I will begin with a very rudimentary (but working) PHP script to take input from a feedback form and send it to you in an email message.

If you are programming-savvy, you will recognize this as a sort of "Hello World" program, but infinitely more useful! Writing the Feedback Form The first thing we need to do is to write the feedback form itself. The Feedback Form PHP Script Now all that remains is to code "sendmail.php". Conclusion. Instruction separation. Variable scope. The scope of a variable is the context within which it is defined. For the most part all PHP variables only have a single scope.

This single scope spans included and required files as well. For example: Here the variable will be available within the included script. However, within user-defined functions a local function scope is introduced. Any variable used inside a function is by default limited to the local function scope. <? Function test(){ echo $a; /* reference to local scope variable */ } test();? This script will not produce any output because the echo statement refers to a local version of the variable, and it has not been assigned a value within this scope.

The global keyword First, an example use of global: Example #1 Using global <? Function Sum(){ global $a, $b; $b = $a + $b;} Sum();echo $b;? The above script will output 3. A second way to access variables from the global scope is to use the special PHP-defined array. Example #2 Using instead of global Using static variables <? <? <? <? PHP: extends - Manual. Basics.