Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-07-2008, 01:08 AM
Junior Member
 
Join Date: Mar 2008
Posts: 7
Question Subclassing the Action Controller

Hi, I'm looking for a quick tutorial on subclassing the action controller. The docs (Zend Framework: Documentation) don't say very much about it.

Basically, I'm realizing I'm repeating a bit of code every time I create a new controller. I would like to include the following function in the base controller that extends the zend_controller_action which I could then extend it with my normal page controllers.

For example, I would like all of my controllers to have the following function:

public function init()
{
$this->view->baseUrl = $this->_request->getBaseUrl();
}

Thanks!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-07-2008, 06:31 PM
xentek's Avatar
Senior Member
 
Join Date: Feb 2008
Posts: 112
Default

Here's the basic BaseController
PHP Code:
class BaseController extends Zend_Controller_Action
{
     
// put your methods here
     
public function commonFunction()
     {
         
// do something
     
}

Here's your other controllers extending BaseController:
PHP Code:
class OtherController extends BaseController
{
     
// put your action methods here
     
public function someAction()
     {
           
$this->commonFunction();
     }

This should get you started.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-14-2008, 03:27 PM
Junior Member
 
Join Date: Mar 2008
Posts: 7
Default

Thanks Xentek for the help. I'm hoping you don't mind lending your expertise once again. Over in this thread I had some issues with pathing. And I thought they were solved. Here's issue:

I currently have the following structure:

/library/Erik/controllers
/library/Erik/forms
/library/Zend/

In my indexAction, I am able to require_once 'form/myNewForm' without any issues. However, when I attempt to require_once 'controllers/BaseControllers/ PHP throws an error (can't find the file). Any ideas...it's maddening!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-14-2008, 05:23 PM
Junior Member
 
Join Date: Mar 2008
Posts: 7
Default

I was able to get the controller loaded, but I'm still not completely understanding the pathing issue. I'm having another developer take a look at the issue for me this afternoon, so I'll post an update when I have one.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 03-14-2008, 05:39 PM
Junior Member
 
Join Date: Mar 2008
Posts: 15
Default

Do you want to try registerAuotLoad() in Zend?? In this way you dun need to require classes yourself manually.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 03-14-2008, 06:57 PM
Junior Member
 
Join Date: Mar 2008
Posts: 7
Default

I've tried that and it works, but I'm still learning and didn't want to depend on it in hopes it would always work.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 03-17-2008, 06:29 AM
kmg kmg is offline
Junior Member
 
Join Date: Mar 2008
Posts: 9
Default

Well, naming your application directory "library" seems like a bad start, as one could take that to mean that the directory actually houses the thing that most resembles a library, that is, the Zend Framework. It also sounds like you're having simple include_path issues. Basically you need to have an entry in your include_path for every directory you're going to be including files from, or just use the path when actually including the file.

PHP: Description of core php.ini directives - Manual
PHP: set_include_path - Manual
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 03-17-2008, 08:31 PM
Senior Member
 
Join Date: Jan 2008
Location: chicago
Posts: 101
Default

Quote:
Originally Posted by kmg View Post
Well, naming your application directory "library" seems like a bad start, as one could take that to mean that the directory actually houses the thing that most resembles a library, that is, the Zend Framework.
My understanding is that he WAS referring to the library directory not the application directory. notice he also included '/library/Zend/'
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 03-18-2008, 06:08 PM
xentek's Avatar
Senior Member
 
Join Date: Feb 2008
Posts: 112
Default

@ehalber

I agree with KMG... I think you may want to rethink your dir structure and check out the autoLoader. The only thing I'm putting my library directory, besides Zend is other third-party libraries I'm using.
__________________
- xentek
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 04:12 AM.