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

  • Home
  • SEARCH
  • 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 7763155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:35:39+00:00 2026-06-01T14:35:39+00:00

I have a model class ModelHome that is a child of Model ie: class

  • 0

I have a model class ModelHome that is a child of Model ie:

class ModelHome extends Model

Model is a variable of the Controller class ie:

class Controller {

    public $model;

    public function __construct () {
        $this->model = new Model;
    }
}

Is it possible to access a method within the Controller class from within a method inside the ModelHome class?

I’ve tried parent:: and calling the class by name ie Controller::method but I can’t seem to find the right scope to access the method I need.

Thanks.

-Vince

  • 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-01T14:35:40+00:00Added an answer on June 1, 2026 at 2:35 pm

    First of all, you must have an instance of ModelHome. If you make an instance of Model, that has not automatically been extended by ModelHome just because ModelHome exists. So, i guess your Controller::__construct() should be:

    public function __construct () {
        $this->model = new ModelHome;
    }
    

    However, your ModelHome does not know about your Controller class/instance. You could make a __construct in ModelHome that takes a parameter with a link to the controller. Like this:

    class ModelHome extends Model {
    
        public $controller;
    
        public function __construct ($controller) {
            $this->controller = $controller;
        }
    }
    
    class Controller {
    
        public $model;
    
        public function __construct () {
            $this->model = new ModelHome($this);
        }
    }
    

    Now, your ModelHome knows about the controller by using $this->controller

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

Sidebar

Related Questions

I have a model: class Service extends CActiveRecord { public static function model($className =
I have Model class like this class ModelName { public static void createTable(SQLiteDatabase db){
I have model public class UploadOptionModel { public UploadOptionModel() { OutputFormat = outputFormatList.Select(i =>
I have a model class like this: class Note(models.Model): author = models.ForeignKey(User, related_name='notes') content
I have a model class that uses a custom validator as shown in following
Assume I have this model : class Task(models.Model): title = models.CharField() Now I would
Let's say I have a model class called Project, but instead of this: class
I have model public class MyModel { public string Name { get; set;} }
I have model public class GrandPrix { public int Id { get; set; }
I have this model: class Location < ActiveRecord::Base acts_as_gmappable def gmaps4rails_address #{self.city}, #{self.country} end

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.