Hi Bart

Thanks for getting back to me. Apologies for the delay in my response, I've
been away :)


Bart McLeod wrote:
> 
> 
> James Hargreaves wrote:
>> 
>> Hello
>> 
>> I am trying to implement some functionality via a couple of Controller
>> Plugins - my requirements are as follows:
>> 
>> 1) load custom configuration and make this information available in the
>> view
>> 2) check the input URL contains a language code and re-route to holding
>> page (where they can select a language) if it does not
>> 
>> Obviously these are two completely separate requirements, hence I would
>> like to do this using two completely separate plugins.
>> 
>> Anyway, my first question is ... where do I register the plug-in? I am
>> using the Latest Release of ZF. The index.php generated when I created
>> the project does not obviously have anywhere to load my plug-ins. So,
>> instead I have created a new init method in my Bootstrap.php:
>> 
>> protected function _initPlugins() {
>>     $front = Zend_Controller_Front::getInstance();
>>     $front->registerPlugin(new MyPlugin());
>>     $front->registerPlugin(new MyOtherPlugin());
>> }
>> 
>> Is that the right way to do this? If I register the plug-ins this way
>> will all hooks into the application stack (eg - routeStartup,
>> dispatchLoopStartup, etc) be available to my plug-in?
>> 
> Yes, it is the right way to do this, but I don't see why you put it in a 
> function. Is this inside your bootstrap class? In that case I understand.
> 

Yes, this is in my Bootstrap class, so I think this makes sense as you
suggest.


Bart McLeod wrote:
> 
> 
> James Hargreaves wrote:
>> 
>> Okay, so assuming what I have done above is okay, onto plug-in (1).
>> 
>> I have a configuration file custom.ini that contains, among other things,
>> a Google Maps API key. I want to make this information available in all
>> views throughout the application, so I would do something like:
>> 
>> class MyPlugin extends Zend_Controller_Plugin_Abstract {
>>     public function routeStartup(Zend_Controller_Request_Abstract
>> $request)
>>     {
>>         $config = new Zend_Config_Ini('/path/to/config.ini', $this->env);
>>         $this->view->google_maps_api_key = $config->google_maps_api_key;
>>     }
>> }
>> 
> I would say Zend_Registry::set('my_config', $config);
> 
> and retrieve this whenever you need it as Zend_Registry::get('my_config');
> 

Ah, that is what I am doing at the moment. I was just thinking that there
must be an easier way, but perhaps not.

So, is there no way to access the view object when in a plugin? That seems
like a bit of a limitation to the plug-in method if so, I might have to
write a generic controller class to extend if that is the case, as I would
like to set something on the view throughout the application.


Bart McLeod wrote:
> 
> 
> James Hargreaves wrote:
>> 
>> Is that going to work? I am assuming that $this in this context is not
>> actually the Zend_Application, so $this->env will not yield anything
>> useful, likewise setting anything on $this->view is not going to make
>> this attribute available in the view. Is there someway to access the
>> application via $this - eg - $this->application->env.
>> 
>> Onto plug-in (2). I don't really have any idea how to implement this, but
>> my initial thoughts are:
>> 
> I don't have time to read all this, but I think you should be looking at
> using a custom route.
> $router = $front->getRouter();
> $router->addRoute(-your new route-);
> 
> -Bart
> 

Thanks, I will take a look at defining a custom route as you suggest.


James Hargreaves wrote:
> 
> - http://www.mydomain.com/ should show a holding page, where a language
> can be selected
> - http://www.mydomain.com/<lang>/ (where <lang> is a two-character
> language code such as 'en' or 'de') is the home page for the
> language-specific version of the site
> - http://www.mydomain.com/<lang>/abc/ is a specific page on the
> language-specific site
> 
> - the plug-in should check a valid language code is provided in the URL
> and redirect accordingly.
> - I don't want to provide duplicate controllers for each language, so the
> following URLs should use the same controller:
> 
> http://www.mydomain.com/en/abc/
> http://www.mydomain.com/de/abc/
> 
> In each case the view script should be <lang>.phtml, as oppose to the
> default index.phtml, so that the language of the page can be easily
> defined.
> 
> The last bit is just thinking outloud. It might be easier to accomplish
> what I want by splitting the views by the language at the top level of the
> hierarchy - eg:
> 
> APPLICATION_PATH/views/scripts/en/abc/index.phtml
> 
> As oppose to:
> 
> APPLICATION_PATH/views/scripts/abc/en.phtml
> 
> I don't really mind either way. But I definitely do not want to duplicate
> the controllers.
> 
> Anyway, that's what I need to do. Apologies for the lengthy post, but as
> you can see there are quite a few issues I need to address, I think mainly
> because I am new to ZF and still not fully sure how it all hangs together.
> Any help would be appreciated :)
> 
> Thanks
> Jay
> 

I keep seeing talk of "modules" on some ZF posts, how does this work and is
this something I could use?

Thanks
Jay
-- 
View this message in context: 
http://www.nabble.com/Front-Controller-Plugin-Problems-tp24642509p24678646.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to