Posts

MySQL Command Line Client's pager/nopager Options

I use screen to manage my servers so I don't lose my place when my computer goes to sleep. It's great but it makes it hard to scroll back if you run a command that takes up more than a single screen. It's easy for normal command line items because you can run it through more or less but MySQL could be a problem.

There is a very simple fix in order to read all the results.

mysql> pager less
PAGER set to 'less'

Then to disable the pager setting.

mysql> nopager
PAGER set to stdout

Things I Learned While Writing a Timezone Aware Website in PHP

I've just finished my first PHP application that had to handle dates and time spans correctly across multiple timezones and I thought I would share a couple of the things that I learned. Read More

How to Get the Current User Name and Group PHP is Running Under

I wrote a script today that makes sure the apache process has write access to specific folder in my path (mostly upload directories) and I wanted to give the administrator account a list of the commands to run in order to fix the permissions.

To get the current user name:

$userInfo = posix_getpwuid(posix_getuid());
$user = $userInfo['name'];    

To get the current group name:

$groupInfo = posix_getgrgid(posix_getgid());
$group = $groupInfo = $groupInfo['name'];

Determine If Today Is the Last Day of the Month in PHP

If you have a report or process that only needs to run on the last day of the month you can use the following code to determine if today is the end of the month:

if(gmdate('t') == gmdate('d')){
    echo 'Last day of the month.';
}

Using Zend's JSON Helper

On my current project, we've had to do a lot with requests that return JSON for the dynamic form elements. Normally, I would disable the view (so I didn't need another blank file hanging around), disable the layout, and then echo out the results of json_encode(). It turns out that Zend has a build in function to do this in one command from the Controller:

$this->_helper->json($data, true);

Link Post: Pictures From a Developer's Live

I can totally relate to these:

http://martinvalasek.com/blog/pictures-from-a-developers-life

Via reddit

Making It Easier to Access The Options in Zend Framework

If you use the application.ini config file to store differences in production and testing environments (I highly recommend it) it can be annoying to access the settings. Getting the Bootstrap first and then retrieving the settings file can be annoying and error prone.

It turns out there is a much simpler way to handle this. First add the following to your Bootstrap file:

protected function _initSaveSettings(){ 
    Zend_Registry::set('options', $this->getOptions()); 
}

Then whenever you need the options you can do the following:

$options = Zend_Registry::get('options');
$setting = $options['settingName'];

Or if you're using PHP 5.4+ (I've already been burned by this twice so don't do it if you can't be sure) you can do this:

$setting = Zend_Registry::get('options')['settingName'];

Finding All Tables in the Current Database Using Zend Framework

I needed to get a listing of all the table in our database (I was building a global trashcan so users could restore their own data without bothering us programmers). I thought I would need to do something painful like create a custom query and loop through the results but it turns out it takes two lines of code:

$db = Zend_Db_Table::getDefaultAdapter(); 
$allTables = $db->listTables();  

Another amazingly well done piece of the Zend Framework.

Using a Zend Partial Inside a Model

Zend's partial view helper is great because it allow you to reuse the same HTML code repeatedly in multiple layouts and views but it can be used for so much more. For example, I'm working on a project that sends a large amount of email. Usually, I want to send these emails in response to something happening inside a model (new user signup, password reset, etc.). Ideally, I would be able to generate the email using the partials and not by inlining all the HTML in the model (which would have been my old approach) but you can't access the partial view helper directly from inside the model.

The code below creates a new Zend_View and sets it up so the partial view helper will work. I send out both an HTML and a text body for the emails so I create two separate view files so it's still easy to maintain.

$view = new Zend_View();
$view->setBasePath(APPLICATION_PATH . '/views/');
$emailBodyHTML = $view->partial('email/registrationEmail.phtml', array('values'=>$values));
$emailBodyText = $view->partial('email/registrationEmail.txt', array('values'=>$values));

To simplify things even more in my actual code base, I have extended Zend_Email so we only need to call one function to get this functionality.

$mail = new Application_Model_Email();
$email->setEmailBoth('registrationEmail', array('values'=>$values));

Happy Valentines Day!

RSS

Join Our Mailing List!

View previous campaigns.

Top Posts

  1. Working With Soft Deletes in Laravel (By Example)
  2. Fixing CMake was unable to find a build program corresponding to "Unix Makefiles"
  3. Upgrading to Laravel 8.x
  4. Get The Count of the Number of Users in an AD Group
  5. Multiple Vagrant VMs in One Vagrantfile
  6. Fixing the "this is larger than GitHub's recommended maximum file size of 50.00 MB" error
  7. Changing the Directory Vagrant Stores the VMs In
  8. Accepting Android SDK Licenses From The OSX Command Line
  9. Fixing the 'Target class [config] does not exist' Error
  10. Using Rectangle to Manage MacOS Windows

subscribe via RSS

All content copyright This Programming Thing 2012 - 2021
Blogging about PHP, MySQL, Zend Framework, MySQL, Server Administration and Programming in general