This might sound trivial but an advantage of using base controllers is that you 
get code completion using eclipse or zend studio.

Do you get code completion when using action helpers?

For example it would be great if you could go $this->_helper->[List of all 
available helpers]



-----Original Message-----
From: Marko Korhonen [mailto:[email protected]]
Sent: 19 February 2009 20:27
To: [email protected]
Subject: Re: [fw-general] Base Controller convienience methods



Ok, done.

Now I have converted most of the methods in my base controllers as action
helpers, plugins or just moved them to views.

I have the final challenge:

I declare "blocks" to my sidebar with my new action helper "Block".

Example, $this->_helper->block($block, "left_sidebar", 0); // renders $block
object to left sidebar as first block

BUT. I want to add some blocks in every module/controller/action or in every
action/somecontroller.

Before I added these helper calls to my base controller but now I don't have
base controllers.

So, next I tried plugins. Well, I can't access current controller.
Ok, I could use action helpers. BUT, then I need to add these helper calls
to every controller...

I was thinking about following:

Somekind of Hook system.
-should go through $frontController->getModuleDirectory() to get every
module
-should check if some file exists in the moduledir
-if file exits, it should be loaded, and if the class "Module_Hook" exists,
it should make new Module_Hook();
-Now it gets tricky...
-where to add event calls ? Hook:someEvent($args);
-Can this Hook class have access to needed resources, for example action
helpers

what, where, why o why!!

br, Marko (drinking beer)



Matthew Weier O'Phinney-3 wrote:
> 
> -- Marko Korhonen <[email protected]> wrote
> (on Monday, 16 February 2009, 05:04 AM -0800):
>> I'm pretty sure that others have done the same as me:
>> 
>> Base Controllers like My_BaseController and used as follows:
>> Module_SomeController extends MyLibrary_Controller_Base
>> 
>> Well, if so, you probably have done some methods just to shorten things a
>> bit.
>> 
>> I'll share some of my "convienience" methods and I hope you got some
>> ideas/feedback/bugs noticed and maybe some great convienience methods to
>> share...
>> 
>> I still would like to get Module Base Controller, but it does not
>> autoload
>> itself =(
>> Module_SomeController extends Module_BaseController
> 
> This is what action helpers were designed for -- to allow for common
> functionality between action controllers, and also for distributing
> functionality to use in different projects. If I may, I'd recommend
> rewriting these as action helpers.
> 
> One change I'm going to add before 1.8 is the addition of a
> "getHelperBroker()" method to both the action controller and abstract
> action helper (this latter will proxy to the action controller). This
> will allow your action helpers to have access to other action helpers
> trivially. For example:
> 
>     $this->getHelperBroker()->json($data);
> 
> This should help with re-use, and further eliminate reasons for "base"
> controllers in your projects.
> 
>> -------------------------------------------------------------------
>> 
>> // output json without rendering any layouts/templates
>> protected function json($data)
>> {
>>      $this->_helper->json($data);
>> }
>> 
>> // Is the current action frontpage
>> protected function isFrontpage()
>> {
>>      $front = $this->getFrontController();
>> 
>>      return (boolean) $this->_module == $front->getDefaultModule() &&
>> $this->_controller == $front->getDefaultControllerName() &&
>> $this->_action
>> == $front->getDefaultAction();
>> }
>> 
>> // Disable layout and/or viewRenderer
>> protected function disableUI($layout = true, $viewRenderer = true)
>> {
>>      if ($layout) $this->_helper->layout->disableLayout();
>>              
>>      if ($viewRenderer) $this->_helper->viewRenderer->setNoRender();
>> }
>> 
>> // Set layout
>> protected function setLayout($layout)
>> {
>>      $this->_helper->layout->setLayout($layout);
>> }
>> 
>> // Set template
>> protected function setTemplate($template)
>> {
>>      $this->_helper->viewRenderer($template);
>> }
>> 
>> // Change the response segment (default is being $this->layout()->content
>> protected function setResponseSegment($segment)
>> {
>>      $this->_helper->viewRenderer->setResponseSegment($segment);
>> }
>> 
>> // Set page title
>> public function setTitle($title)
>> {
>>      $this->view->headTitle($this->view->page_title);
>> }
>> 
>> // Get Url by default route
>> public function url($module, $controller, $action, array $urlOptions =
>> array(), $reset = false, $encode = true)
>> {
>>      $urlOptions["module"] = $module;
>>      $urlOptions["controller"] = $controller;
>>      $urlOptions["action"] = $action;
>>              
>>      return $this->view->url($urlOptions, "default", $reset, $encode);
>> }
>> 
>> // Get Url by named route
>> public function urlByName($name, array $urlOptions = array(), $reset =
>> false, $encode = true)
>> {
>>      return $this->view->url($urlOptions, $name, $reset, $encode);
>> }
>> -- 
>> View this message in context:
>> http://www.nabble.com/Base-Controller-convienience-methods-tp22036897p22036897.html
>> Sent from the Zend Framework mailing list archive at Nabble.com.
>> 
> 
> -- 
> Matthew Weier O'Phinney
> Software Architect       | [email protected]
> Zend Framework           | http://framework.zend.com/
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Base-Controller-convienience-methods-tp22036897p22108968.html
Sent from the Zend Framework mailing list archive at Nabble.com.


This mail has originated outside your organization, either from an external 
partner or the Global Internet.
Keep this in mind if you answer this message.



This e-mail and any attachment may contain confidential and/or privileged 
information. If you have received this e-mail and/or attachment in error, 
please notify the sender immediately and delete the e-mail and any attachment 
from your system. If you are not the intended recipient you must not copy, 
distribute, disclose or use the contents of the e-mail or any attachment. 
All e-mail sent to or from this address may be accessed by someone other than 
the recipient for system management and security reasons or for other lawful 
purposes. 
Airbus UK Limited is registered in England and Wales under company number 
3468788. The company's registered office is at New Filton House, Filton, 
Bristol, BS99 7AR.


Reply via email to