Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7857689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:06:58+00:00 2026-06-02T21:06:58+00:00

I am trying to build an abstract base controller that will extend all other

  • 0

I am trying to build an abstract base controller that will extend all other controllers. So far I have something like:

    abstract class BaseController {

     protected $view;
     protected $user;

     public function __construct() {
       $this->view = new View; //So a view is accessible to subclasses via $this->view->set();
       $this->user = new User; //So I can check $this->user->hasPermission('is_admin');
     }
     abstract function index();

    }

class UserController extends BaseController {

  public function index() {}

  public function login() {

  if($this->user->isLoggedin()) {
   redirect to my account
  }
  else {
      $this->view->set('page_title', "User Login");
      $this->view->set('sidebar', $sidebar); //contains sidebar HTML
      $this->view->set('content', $content); //build main page HTML
      $this->view->render();

}
}
}

The problem i get is I get errors like this:

Call to a member function set() on a non-object in C:\xampp\htdocs\program\core\controllers\admin.controller.php on line 44

If I put the $user and $views properties in the main controller (ie UserController), everything works fine. But I only want to set up these objects once (in the base controller) and not have to add $this->view = new View; in all my controllers.

FIXED: I overrode my constructors and I thought you couldn’t call parent::__construct() on abstract classes.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T21:07:00+00:00Added an answer on June 2, 2026 at 9:07 pm

    What you are trying to do should work. Make sure you aren’t covering up your constructor in UserController. (i.e., if it has a constructor, it needs to call its parent constructor.)

    Otherwise, do some debugging to see where $this->view is being reset.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that inherits from an abstract base class. I am trying
I am trying to build a simple abstract Cache class that can enforce methods
I'm trying to build a download manager class that packets all the async download
I'm trying to have an abstract base class for some builder classes so I
I am trying to build a program using model-view-controller. Specifically: I have a state
I'm trying to understand the IntentService class so that I can build my own
I'm trying to build a factory method that uses the generics feature of C#.
I'm trying to use the Android tutorial to build an app that loads a
Background: Hello I am trying to build a windows workflow like state engine. I
I'm trying to create a base class that provides a good amount of re-usable

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.