There's nothing stopping you from adding custom autocomplete rules to Eclipse
for your team members.
In fact, you'd have to if you want to achieve that level of functionality. The helper's are lazy
loaded through a broker system which relies on magic methods, so there's no way eclipse can figure
out what's going on.
You can easily trick eclipse into having additional code completion by having a dummy file(s) in
your project, where you explicitly declare some variable types.
All it would take is for your guys to maintain a file like this, which is on the include path of the
project:
class HelperFaker {
/**
* Enter description here...
*
* @var Zend_Controller_Action_Helper_Url
*/
public $url;
/**
* Enter description here...
*
* @var Zend_Controller_Action_Helper_ViewRenderer
*/
public $viewRenderer;
}
And then just rehint what $_helper is in the controller classes:
/**
* @var HelperFaker;
*/
protected $_helper;
But then again, it may just be prudent for all the developers to actually become familiar with the
medium they're working with and properly maintain the project's API docs.
On 24/02/2009 8:42 AM, O'BRIEN, Steven X wrote:
Hi Jake,
Ok this is getting fussy. But we are finding that despite there being pre written
classes people still write helpers that already exist. Because they don't know they
exist. The Zend framework has a lot of files. Combine these with your own project
specific files and you have a lot of helpers. The time it takes looking to see if
the helper exists or trying to remember what it was exactly called you could have
written another! Working in a team with new starts its much better when you can just
say: Oh yeh to access the helpers just type $this->_helper-> and look through
the list that pops up... If you cant find what you want there then feel free to write
your own (which will get automatically picked up and added to the list by the IDE.
This is coming from a .net C# background for desktop apps using visual studio.
You don't realise how much you miss this feature until its gone. PHP and PHP
based IDE's are definitely heading in the right direction, i just want more
more more :-)
-----Original Message-----
From: Jake McGraw [mailto:[email protected]]
Sent: 24 February 2009 16:23
To: O'BRIEN, Steven X
Cc: Marko Korhonen; [email protected]
Subject: Re: [fw-general] Base Controller convenience methods
Steven:
To get code completion do something like:
/**
* @var MyCustomHelper
*/
protected $myCustomHelper;
...
public function init() {
...
$this->myCustomHelper = $this->_helper->myCustomHelper;
...
}
using the @var notation will allow Eclipse to expand any reference.
- jake
On Tue, Feb 24, 2009 at 9:23 AM, O'BRIEN, Steven X
<[email protected]> wrote:
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.
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.