PHP, MySQL, JavaScript, Windows 7, Linux
Zend Framework
Zend Framework 2.0 Buzz
Mar 3rd
The buzz behind Zend Framework 2.0 is growing rapidly everyday, and not without good reason. Zend Framework 2.0 will utilize the very best of PHP to create a more stable, secure, and better performing framework. Although nothing is set in stone, listed below are some of the highlights so far:
- Minimum version: PHP 5.3+
- Not backwards compatible
- Improved consistence between componenets
- __construct() – Constructors will accept options via arrays or Zend_Config
- Option keys will not use camel caps or uppercase, but instead will utilize lowercase underscore-separated words
- Elimination of most singletons
- Utilization of PHP 5.3 features
- __invoke() and closures – for use within plugin architecture
- Namespaces – to help with the super-long class names (Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive comes to mind)
- goto – to be used when creating Finite State Machines (FSM) and parsers (Zend_Search_Lucene, Zend_Ical, Zend_Markup)
- Autoload-only for all ZF components
- Zend_View
- Allow optional use of streams for systems where short_open_tags are disabled
- Automatic escaping of variables
- Use PluginLoader instead of internal system for managing plugins
There’s a lot of great discussion going on within the official Zend Framework 2.0 Roadmap, as well as a general outline on Zend’s plans, so get over there and read up!
Zend_Search_Lucene_Analysis_Analyzer_Common_TextNum_CaseInsensitive
Using PHPass password hasher with Zend Framework
Oct 7th
In this tutorial, we will learn how to use PHPass, a portable PHP password hashing component, with the “glue”-based Zend Framework. The popular PHP-based blogging platform WordPress utilizes PHPass to hash user passwords. Using this library adds an extra level of security over a normal MD5-protected password. Read the rest of this entry »
Simple handling of jQuery dependencies with Zend Framework 1.9.x
Sep 25th
I have a lot of experience with WordPress development, and I’ve grown to love the way JavaScript dependencies are handled in that particular application. In WordPress, all JavaScript dependencies are defined in /wp-includes/script-loader.php. To ensure jQuery loads before any jQuery-dependent scripts, you just use $script->add() and reference the jQuery library ID. Easy as pie. Read the rest of this entry »
Passing parameters with Route in Zend Framework
Sep 14th
When first approaching the Zend Framework, it almost appears that in order to get URLs like /controllername/page1 or /controllername/page2 (equivalent to /controllername/?varname=page1 w/o ZF) with their preconceived directory structure, you have to create a new action for each new page in order to serve the page. This would ultimately mean a new function for every single page within that controller; however, with Zend_Controller_Front and Zend_Controller_Router_Route, we can avoid this and pass page1, page2, and any other string as variables. Read the rest of this entry »
Adding default database table prefixes in Zend Framework 1.9.x
Sep 8th
Recently, I began working with Zend Framework 1.9.2 to restructure one of my web sites. I learned how to create an extension of the Zend_Db_Table_Abstract from a great “Getting Started” tutorial, but I found myself rewriting the table prefix with each and every new table. Below I explain one solution to this problem, but I am new to Zend Framework, so please feel free to recommend a better, more integrated way of doing this, if you know of anything.
Step 1: application.ini
Place the following code in your /application/configs/application.ini file:
[production] table_prefix = "webjawns_"
Step 2: TPC_DB_Table_Abstract class
Create a new class in the library directory. For this example, we’ll use TPC_DB_Table_Abstract as the name, which will be stored in /library/TPC/DB/Table/Abstract.php.
<?php
class TPC_DB_Table_Abstract extends Zend_Db_Table_Abstract {
protected function _setupTableName() {
global $application;
parent::_setupTableName();
$prefix = $application->getOption('table_prefix');
$this->_name = $prefix . $this->_name;
}
}
Step 3: /application/Bootstrap.php
After that, you’ll want to make sure that the new Abstract.php file is referenced in your /application/Bootstrap.php file.
protected function _initAutoload() {
$moduleLoader = new Zend_Application_Module_Autoloader( array(
'namespace' => '',
'basePath' => APPLICATION_PATH ) );
$moduleLoader->addResourceType('', '../library/TPC', 'TPC');
return $moduleLoader;
}
Step 4: /application/models/DbTable/NewTable.php
To use the table prefix, we will basically be substituting Zend_Db_Table_Abstract with TPC_DB_Table_Abstract. See the example below:
class Model_DbTable_NewTable extends TPC_DB_Table_Abstract {
// Database name will be $prefix + $_name
protected $_name = 'newtable';
}
This is just one way to create default table prefixes for each of your tables. I’m sure this isn’t the only way, and there may even be better, easier ways to do this. As an added bonus, we use the TPC_DB_Table_Abstract class to extend the Zend database functionality even further. If anyone else has any ideas about how to use default table prefixes (other than using a constant), please feel free to share them so we can all benefit.