Hello,
Thanks about this, well, i did precisely that somewhile ago and i got
an exception thrown that the controller was not an instanceof
Zend_Controller_Action.
Now either i was being really dumb (happens :) ) or this restriction was
removed (sorry i don't have the time to dig this issue) the thing is i
tried it now with latest svn (219 rev) and it's working, so thumbs up
and completely ignore the part of my email where i mention it.
Thanks both, best regards,
Rui Barreiros
Stephane Crivisier wrote:
Hi all :)
On 4/18/06, Ralf Eggert <r.eggert-NdIitsehInIb1SvskN2V4Q@xxxxxxxxxxxxxxxx>
wrote:
Hi Rui,
One of the things i hate the most is repetition, honestly i think that
the requirement of the controller to be extended from
Zend_Controller_Action should be removed, simply because imagine i have
the need to setup something at all my controllers constructor, or add a
method wich will be always the same for all my controllers, i will have
to write always the same piece of code into all my controllers, so i
would love to be able to do this:
class MyApplication_Controller_Action extends Zend_Controller_Action {
function __construct()
{
// do my repeating code here
}
protected function myrepeatablefunction()
{
}
}
class IndexController extends MyApplication_Controller_Action
{
public function indexAction()
{
echo "blah";
}
}
If I understand you correctly, you already can do this with almost no
hassle. Just create a new subdirectory below your include_path to the
Zend Framework. There is a nice example in the Zend Framework manual [1].
I think you understand him correctly...
Have a look at this directory structure (Widget can be replaced by your
own company name or whatever).
/library
/Zend
/Widget
/Controller
Action.php
README.txt
The Action.php could look like this:
class Widget_Controller_Action extends Zend_Controller_Action
{
public function __construct()
{
// do your controller stuff
}
public function indexAction()
{
}
protected function myrepeatablefunction()
{
}
}
The only problem is that you have to declare an empty indexAction()
function since the indexAction() in the abstract Zend_Controller_Action
class is also declared as abstract.
I can't agree that point.
You can declare your class as an abstract class like this:
abstract class Widget_Controller_Action extends Zend_Controller_Action
{
public function __construct()
{
// do your controller stuff
}
protected function myrepeatablefunction()
{
// do your other stuff...
}
}
Now you can't instanciate a Widget_Controller_Action but you cant extend it :
class IndexController extends Widget_Controller_Action
{
public function indexAction()
{
myrepeatablefunction();
// do whatever you like
}
}
IndexController have to implements indexAction() because this method
is an abstract method from Zend_Controller_Action.
Hope that can help both of you ;)
Best regards
PS: sorry for my english
--
Stéphane Crivisier
Étudiant à l' {EPITECH.}
|
|