Joey Adams Dot Net

Southern Fried Programming


Archive for the ‘php’


Home Server Speed + Development Changes

Last week I moved everything in a couple rooms of the house around, and now my workstation and server cabinet are in my room (and it hot as hell, I run like 4 electric fans + ceiling fan just to cool down).

I am now in a situation, which is fun for any enthusiast. I love redoing the network, or just working on it. I am seeing some speed issues with this site, and my other projects. Of course these are not meant to be highly available or that fast anyway, but they are suffering performance issues greatly.

 I am suspecting the Rackmount Hub I have in the cabinet that hooks the servers together with the network. I am going to try to get a rackmount switch, and see if that helps out, which it should.

The network environment is a mess right now, although an ordered mess, haha. I need to build the rest of a PC  to have in the living room to power the extender for my home PVR, I am going to just use a crossover cable to connect the two, then connect the pc wirelessly to the network to get updates and guides.

The windows server is not doing the print server correctly, nor have I finished setting up the fax, because I lack another phone. So if you call the house 3 times, you get data tones :) .

I have also switched my development flow to using subversion, and never t0uching production folders. I am using WebDrive to map the projects directory to my pc, and using ZendStudio’s svn functions to make changes to the trunk of the projects repo, which runs on the windows server. Whenever I am ready to show a client a new feature, I copy the trunk to the staging branch, and update the staging directory.

The staging server is password protected so only me and the client can see development. The development server is only accessible to my local network. Once the client approves the changes, I will copy the staging branch to the live branch, then update the live(production) folder.

 This effectively makes several backups of the source, at different states, on different harddrives, and I never have to touch files in the production environment, this is a very important concept.

Just a note on Zend Studio, also note I am using ZS for Eclipse. I really wish it had some type of remote-svn project resource. Or even a remote-project resource that you could have say a ‘php’ or ‘framework’ project without hacking up the project settings. It just made it very difficult to use its built-in project settings with svn on a remote server, which is a very very common development environment. 

Zend just has never been very good with community support. I am not sure about their product support, but the forums are a ghost town, and offer not much help, and emailing them does hardly any good, ALTHOUGH it may have changed.

I submitted several requests on a lot of different emails about my profile in the zend yellow pages after getting my ZCE , because I could not edit the details, this was about a year and a half ago, I just now a few weeks ago received an email saying it was fixed haha.

So maybe they have a new support team.

I will write up some network statistics after changing, and a how-to for subversion development at home.

Breadcrumbs with Zend Framework

I was integrating breadcrumbs into a site I am currently building and figured I would share the code I used to make it possible.

This project uses a MODULAR layout, so theres no solutions out there that helped me out. I wanted it to display cleanly, without displaying things like ‘default’ as the module name, and not to display a breadcrumb if it was the home page (ie. default module, index controller, index action).

 Basically it is a view helper that you call, and it fetches everything for you.

Some things to know. It pulls  ’siteurl’ from the Zend_Registry, you can change this if you want, well you can change anything you want, it’s nothing special, but it may help someone out there.

 Just add this viewhelper

<?php

/**
* BreadCrumb View Helper
*@author Joey Adams
*
*/
class ViewHelpers_BreadCrumb {

public function breadCrumb() {
$module = Zend_Controller_Front::getInstance()->getRequest()->getModuleName();
$l_m = strtolower($module);

$controller = Zend_Controller_Front::getInstance()->getRequest()->getControllerName();
$l_c = strtolower($controller);

$action = Zend_Controller_Front::getInstance()->getRequest()->getActionName();
$l_a = strtolower($action);

// HomePage = No Breadcrumb
if($l_m == 'default' && $l_c == 'index' && $l_a == 'index'){
return;
}

// Get our url and create a home crumb
$url = Zend_Registry::get('siteurl');
$homeLink = "<a href='{$url}/'>Home</a>";

// Start crumbs
$crumbs = $homeLink . " > ";

// If our module is default
if($l_m == 'default') {

if($l_a == 'index'){
$crumbs .= $controller;
} else {
$crumbs .= "<a href='{$url}/{$controller}/'>$controller</a> > $action";
}
} else {
// Non Default Module
if($l_c == 'index' && $l_a == 'index') {
$crumbs .= $module;
} else {
$crumbs .= "<a href='{$url}/{$module}/'>$module</a> > ";
if($l_a == 'index') {
$crumbs .= $controller;
} else {
$crumbs .= "<a href='{$url}/{$module}/{$controller}/'>$controller</a> > $action";
}
}

}
return $crumbs;
}

}

MYSQL Abstraction Pro + iObject, Powerful Abstraction

I have created a MYSQL abstraction layer that I am pretty proud of.

Here are some of the features:

  • Maintain only one persistent connection to database
  • Can create multiple stored connections at runtime
  • Error Logging
  • Select between 3 return type with each query, including all new iObject
  • iObject (improved Object) has helper methods, and is extensible via Plugin
  • Escape function for variables/array before using them in query
  • Get results in xml or html format, great for reports/test

(more…)

2 Step Views in Zend Framework with Zend_Layout Part 2

In the first part, we looked at the simple way to do 2 step views in Zend Framework prior to 1.5 using a front controller plugin. Now, with the release of 1.5, we have access to Zend_Layout, which is native support for implementing 2 step views.

First off, Visit Akra’s site, there is a lot of information of the Zend Framework there, and a great tutorial on Zend_Layout. You can find the article here, http://akrabat.com/2007/12/11/simple-zend_layout-example/, Also take a look at the official documentation here, http://framework.zend.com/manual/en/zend.layout.html

First off, I’ll assume you have a functioning bootstrap, and working application.

Inside your bootstrap you must start Zend_Layout’s MVC Helper. This can take a number of arguments in array fashion, the most important being the directory that you are going to store the templates in. I suggest views/layouts. See the official documentation for more options.


Zend_Layout::startMvc(array('layoutPath' => '../application/views/layouts'));

Now, before we go further, Here are some methods you can use in the controllers in your application.

(more…)

Zend Framework 1.5 Praise, and Free Skeleton App Download

If you know anything about me and my profession, you know that I am a extreme advocate of the Zend Framework and its standardization of PHP programming, well Zend has just release v1.5 of the framework.

To be honest, I could beat a dead horse by reiterating what is new in 1.5, however I am going to focus on what I have been working with and so far love about the new version.

Also, You can download my compiled skeleton 1.5 project, complete with the 1.5 Library at the end of this article. (more…)

BrokenWeb Security Consulting and Development in the works

I have mentioned a few times possibly starting a IT Security consulting and web development venture. Here lately, while working a full-time job, going to college full-time, taking care of my son, training MMA, and studying for the MYSQL-DEV exams, I don’t have time to put this together.

However in down time I have gone over ideas, talked to some people, and have some pretty neat things planned for this. I have a lot of great ideas for the site, including frequent blogs on security for both business owners and individuals wanting to become more secure. Video demonstrations of how attacks work. (more…)

Fluent Interfaces, the best thing to happen to programming since Array()’s

If you are a programmer, and utilize all the goodness of OOP, and you have not heard of fluent interfaces, then you have been missing out!

Using them further establishes object relationship, tidies up code, and gives access to a whole array of new uses.

A quick example of fluent interfacing is this


company::getInstance()->selectStore(31)->addEmployee(array('fname'=>'Joey','lname'=>'Adams'));

Get It?

Basically, to achieve fluent interfaces, just return object references in methods. This can be (more…)

2 Step Views in Zend Framework With SiteTemplate Part 1

I am a complete advocate of the Zend Framework, it is nothing but good. I will probably post sometime in the near future why I believe it is the best development option out there, but for now we are going to be talking about views.

Views coincide with the framework’s MVC architecture. The view is the presentation, or basically the templates that display the dynamic data manipulated by PHP.

For each Action you have in a controller, you have a view script, which is a phtml file. One solution to creating a uniform site, was on each phtml file, to include header and footers, like this:

<?php echo $this->render('header.phtml'); ?>
<h1><?php echo $this->title; ?></h1>
<?php echo $this->content; ?>
<?php echo $this->render('footer.phtml'); ?>

The problem with this is obvious, redundancy. In case you don’t know, programmers hate redundancy. Once you find yourself repeating code over and over again, in this case, rendering the header and footer, then it is time to create an automated solution. (more…)