Read an interesting way to detect and determine what zend framework components your application uses.
Feels brute force, but it gets the job done.
Article:
Deploy the bare minimum required Zend Framework scripts in your application library
Link:
Read an interesting way to detect and determine what zend framework components your application uses.
Feels brute force, but it gets the job done.
Article:
Deploy the bare minimum required Zend Framework scripts in your application library
Link:
Uploading applications built with Zend Framework (or any other Feature Rich Framework) via FTP/SFTP is just boring and takes too long. Not to mention the size of your own application and additional third party files that you may need to upload to your server.
One solution is to roll your own package that only includes the necessary components, another is to zip, upload and unzip.
For the time being I decided to choose the latter.
With just a quick review of the zip extension on php.net/zip, I found in the documentation a possible solution.
I added my two cents and ended up with this
<?php
$file = basename($_GET['file']);
$extractTo = realpath(dirname(__FILE__)) . '/' . time() . '/' ;
echo "Extracting $file to $extractTo";
$zip = new ZipArchive;
if ($zip->open($file) === TRUE) {
$zip->extractTo($extractTo);
$zip->close();
echo ' - done';
} else {
echo ' - failed';
}
?>
You then do a simple http://www.example.com/unpack.php?file=myapp.zip and your files are extracted in no time.
As you can see nothing fancy.
It creates a new folder within the same location you placed the script . The folder is named after the current timestamp to avoid overwrites.
As per usual, do the necessaries to protect this script.
How do you cut your upload time?
Timezones available:
$form = new Zend_Form();
$timeZoneList = $locale->getTranslationList("timezonetoterritory");
$timeZone = $form->createElement('select', 'time_zone', array(
'filters' => array('StringTrim'),
'label' => 'Time Zone:',
))->addMultiOptions($timeZoneList);
$this->addElement($timeZone);
Allowing users to customize the look of your application is always welcomed. Here is one approach using Zend Framework.
First lets look at the directory structure for creating a themeable application.
Typical Layout:
root
— private
— public
—— css
—— js
—— images
You’ll notice that all our publicly available files for stylesheets, javascript and images are placed in the public folder. We are going to alter this by placing them into a sub-folder under public called ‘default’.
Our structure now looks like this.
root
— private
— public
—— default
——— css
——— js
——— images
What this allows us to do is encapsulate all our files/assets into a single folder that we can now easily reference. All our themes and their assets should now follow the same naming convention as our ‘default’ folder.
Adding a theme to our structure now looks like this
root
— private
— public
—— default
——— css
——— js
——— images
—— modern
——— css
——— js
——— images
In our application bootstrap we add the following line of code (around where you initialize the session)
$session = Zend_Registry::get('Zend_Session'); //change this to match how you store your sessions
if (!isset($session->theme))
$session->theme = 'default';
To easily use this in our application lets create a view helper.
class My_View_Helper_Theme
{
/**
* Returns site base url based on the current theme
*
*
* @return string
*/
public function theme($content = '', $prependBase = true)
{
if ($prependBase)
{
$baseUrl = Zend_Controller_Front::getInstance()->getRequest()->getBaseUrl();
}
else
{
$baseUrl = '';
}
$session = Zend_Registry::get('Zend_Session'); //change this to match how you store your sessions
$url = $baseUrl . $session->theme . $content;
}
}
In our view we can now use our view helper to fetch the correct file from the current theme.
<img src="<?php echo $this->theme('/images/blankslate.jpg') ?>" />
We can make our view helper a little more helpful by adding a fallback to the default if the file doesn’t exist in the theme.
class My_View_Helper_Theme
{
/**
* Returns site base url based on the current theme
*
*
* @return string
*/
public function theme($content = '', $prependBase = true)
{
if ($prependBase)
{
$baseUrl = Zend_Controller_Front::getInstance()->getRequest()->getBaseUrl();
}
else
{
$baseUrl = '';
}
$session = Zend_Registry::get('Zend_Session'); //change this to match how you store your sessions
$url = '/public/' . $session->theme . $content;
$location = DOCUMENT_ROOT . $url;
if (file_exists($location))
{
return $baseUrl . $url;
}
else
{
// If theme doesn't exist then use the default theme
$url = '/public/default' . $content;
return $baseUrl . $url;
}
}