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
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
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'];
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.';
}
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);
I can totally relate to these:
http://martinvalasek.com/blog/pictures-from-a-developers-life
Via reddit
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'];
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.
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));
subscribe via RSS