के भीतर ऐसा करने का मुश्किल हिस्सा ZF ऐप यह है कि संभवतः आपका रखरखाव ऐप को प्रभावित करेगा। इसलिए, यदि रखरखाव के दौरान ऐप "टूटा हुआ" है, तो जोखिम यह है कि "इन-एप" समाधान भी टूट सकता है। उस अर्थ में, "बाहरी" दृष्टिकोण जैसे .htaccess संशोधित करना या public/index.php
फ़ाइल को ट्वीव करना शायद अधिक मजबूत है।
हालांकि, एक "इन-ऐप" दृष्टिकोण फ्रंट-कंट्रोलर प्लगइन का उपयोग कर सकता है। application/plugins/TimedMaintenance.php
में:
class Application_Plugin_TimedMaintenance extends Zend_Controller_Plugin_Abstract
{
protected $start;
protected $end;
public function __construct($start, $end)
{
// Validation to ensure date formats are correct is
// left as an exercise for the reader. Ha! Always wanted
// to do that. ;-)
if ($start > $end){
throw new Exception('Start must precede end');
}
$this->start = $start;
$this->end = $end;
}
public function routeShutdown(Zend_Controller_Request_Abstract $request)
{
$now = date('Y-m-d H:i:s');
if ($this->start <= $now && $now <= $this->end){
$request->setModuleName('default')
->setControllerName('maintenance')
->setActionName('index');
}
}
}
फिर application/Bootstrap.php
में प्लगइन रजिस्टर:
protected function _initPlugin()
{
$this->bootstrap('frontController');
$front = $this->getResource('frontController');
$start = '2012-01-15 05:00:00';
$end = '2012-01-15 06:00:00';
$plugin = new Application_Plugin_TimedMaintenance($start, $end);
$front->registerPlugin($plugin);
}
अभ्यास में, आप config अप करने के लिए प्रारंभ/समाप्ति बार पुश करने के लिए चाहते हो सकता है। application/configs/application.ini
में: बस संपादन config प्रवेश द्वारा
protected function _initPlugin()
{
$this->bootstrap('frontController');
$front = $this->getResource('frontController');
$config = $this->config['maintenance'];
if ($config['enable']){
$start = $config['start'];
$end = $config['end'];
$plugin = new Application_Plugin_TimedMaintenance($start, $end);
$front->registerPlugin($plugin);
}
}
इस तरह, आप रखरखाव मोड सक्षम कर सकते हैं:
maintenance.enable = true
maintenance.start = "2012-01-15 05:00:00"
maintenance.end = "2012-01-15 06:00:00"
तो फिर तुम प्लगइन पंजीकरण तरह देखने के लिए संशोधित कर सकते हैं।
स्रोत
2011-12-31 10:55:32
@Iznogood: संपादन के लिए धन्यवाद। डी 'ओह! ;-) –
कोई समस्या नहीं होती है! :) – Iznogood