-- ZegeeDotCom <[EMAIL PROTECTED]> wrote
(on Monday, 19 March 2007, 07:49 AM -0700):
> include "Zend/Loader.php";
> Zend_Loader::loadClass('Zend_Registry');
> // STAGE 1. Prepare the front ( primary ) controller
> Zend_Loader::loadClass('Zend_Controller_Front');
> $front
> =Zend_Controller_Front::run('../application/controllers');
> $front->setParam( 'view', $view )
> Zend_Loader::loadClass('Zend_View');
> $view = new Zend_View();
> $view->setScriptPath('../application/views');
> $front->setParam( 'view', $view )
>
> and than in the controller:
> $view = $this->getInvokeArg('view');
> $view->header='main_header.tpl.php';
> $view->footer='main_footer.tpl.php';
> $view->actiontemplate ='index.tpl.php';
> $view->index_headline='index_headline.tpl.php';
> $view->index_news='index_news.tpl.php';
> $view->index_packages='index_packages.tpl.php';
> $view->index_analysis='index_analysis.tpl.php';
> $view->index_client_trainer_gym='index_client_trainer_gym.tpl.php';
>
> $this->_response->setBody($this->view->render('index_template.tpl.php'));
>
>
> nothing is displayed...no exception is run...
> do I need to put the whole thing in a try catch clause to see any errrors?
> Has that changed with the 0.9 version also?
This changed way back in the 0.6 release, actually. If you want to catch
or handle exceptions, don't use Zend_Controller_Front::run(). Instead,
try this:
$front = Zend_Controller_Front::getInstance();
$front->throwExceptions(true);
try {
$front->dispatch();
} catch (Exception $e) {
// do something with the exception
}
Handling exceptions with the front controller is well-documented:
http://framework.zend.com/manual/en/zend.controller.exceptions.html
> ZegeeDotCom wrote:
> >
> > NIck -
> >
> > I want to achieve a "singleton" behavior with the view and I thought,
> > that's where the registry comes handy. IF I am using parameters to pass
> > view object back and forth, why is there a registry to begin with?
> >
> >
> > Thanks
> >
> > Paul
> >
> > Nick Lo-2 wrote:
> > >
> > > The now deprecated Zend.php file used to need to be included in the
> > > bootstrap and that was where Zend::registry() was coming from. You
> > > don't specify where you are getting that error but I suspect you've
> > > not actually included the Zend_Registry file...
> > >
> > > include 'Zend/Registry.php';
> > >
> > > ...in your bootstrap.
> > >
> > > Besides that, I'd really recommend from what you outline below that
> > > you simply pass the $view object as a parameter to the controllers:
> > >
> > > In bootstrap...
> > >
> > > $view = new Zend_View();
> > > $view->setScriptPath('../application/views');
> > >
> > > ...then as part of setting up your controller...
> > >
> > > $controller->setParam( 'view', $view )
> > >
> > > ...and then retrieve that in your index controller...
> > >
> > > $view = $this->getInvokeArg('view');
> > >
> > > Nick
> > >
> > >
> > > > WHen I do this in my boot-strapper:
> > > > Zend_Loader::loadClass('Zend_View');
> > > > $view = new Zend_View();
> > > > $view->setScriptPath('../application/views');
> > > > Zend_Registry::set('view',$view);
> > > >
> > > > and this in my default index controller:
> > > >
> > > > $view = Zend_Registry::get('view');
> > > >
> > > > it gives me an error:
> > > > Fatal error: Class 'Zend_Registry' not found
> > > >
> > > > and I have to reinstantiate the view in the controller to get this
> > > > to work.
> > > > This is not right.
> > > >
> > > >
> > > >
> > > >
> > > > Nick Lo-2 wrote:
> > > > >
> > > > > Zend_Registry::set('config',$config);
> > > > > Zend_Registry::get('config');
> > > > >
> > > > > http://framework.zend.com/manual/en/zend.registry.html
> > > > >
> > > > > Also if you're just using that config in a controller you may like to
> > > > > use...
> > > > >
> > > > > $controller->setParam( 'config', $config )
> > > > >
> > > > > ...and retrieve that in the controllers with something like...
> > > > >
> > > > > $this->_config = $this->getInvokeArg('config');
> > > > >
> > > > > Nick
> > > > >
> > > > > On 19/03/2007, at 4:34 PM, ZegeeDotCom wrote:
> > > > >
> > > > > >
> > > > > > Can someone give me an example of how I use the zend registry. I
> > > > > > upgraded to
> > > > > > ZF 0.9 and my zend registry is not working.
> > > > > >
> > > > > > here is the code in my bootstrap file:
> > > > > >
> > > > > > function bootstrap(){
> > > > > >
> > > > > > include "Zend/Loader.php";
> > > > > > Zend_Loader::loadClass('Zend_Controller_Front');
> > > > > >
> > > > > > Zend_Controller_Front::run('../application/controllers');
> > > > > >
> > > > > > Zend_Loader::loadClass('Zend_Registry');
> > > > > > Zend_Loader::loadClass('Zend_View');
> > > > > > $view = new Zend_View();
> > > > > > $view->setScriptPath('../application/views');
> > > > > > Zend_Registry::set('view',$view);
> > > > > >
> > > > > > Zend_Loader::loadClass('Zend_Config_Ini');
> > > > > > $config = new
> > > > > > Zend_Config_InI('../application/config/config.ini','general');
> > > > > > Zend::register('config',$config);
> > > > > >
> > > > > >
> > > > > > }
> > > > > >
> > > > > > How do I register and "deregister" my registers? ;)
--
Matthew Weier O'Phinney
PHP Developer | [EMAIL PROTECTED]
Zend - The PHP Company | http://www.zend.com/