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 9279103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T17:32:56+00:00 2026-06-18T17:32:56+00:00

I have a model class which does not extend any core Zend module .

  • 0

I have a model class which does not extend any core Zend module . This model was imported from my previous Zend framework 1 application . I am able to call its methods by converting it to namespace . The problem what I have is in reading global configuration in side the methods defined .

In case of controller I was able to access global configuration using below code

 $config = $this->getServiceLocator()->get('config'); 

// This gives a union of global configuration along with module configuration .

But what should we do to access configuration in side a model class .
Below is how my model class is

<?php
namespace test\Http; 

class Request
{

    protected $client;

    public function abc( $c)
    {
        return $something;
    } 


    ......

} 

I am new to Zend framework 2 please kindly suggest any method to achieve this .

In the above description model means ( MVC model class ) which has some business logic in it .

  • 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-18T17:32:57+00:00Added an answer on June 18, 2026 at 5:32 pm

    Assuming that you build your service (your code looks like a service) you will probably instantiate it in a service factory (in this case I’ve put it in the module config):

    class MyModule
    {
        public function getServiceConfig()
        {
            return array(
                'factories' => array(
                    'my_request_object' => function (
                        \Zend\ServiceManager\ServiceLocatorInterface $sl
                    ) {
                        $config = $sl->get('config'); 
    
                        return new \GaGooGl\Http\Request($config);
                    },
                ),
            );
        }
    }
    

    This way, you are injecting the config object directly in its consumer (without having a reference to the service locator in the consumer)

    Another way is to implement Zend\ServiceManager\ServiceLocatorAwareInterface in your GaGooGl\Http\Request. I personally discourage it, but this basically allows you to have your Request object keep a reference to the service locator internally, therefore making it possible to retrieve the config service at runtime.

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

Sidebar

Related Questions

I have a simple model class (Part), which pulls from it's information from a
in my zf application i have base model class Application_Model, which connects to db
I have a Query model: class Query < ActiveRecord::Base belongs_to :test end which is
I have a model in my rails application which is class Person < ActiveRecord::Base
i have a class User which extends Ebean Model. And i defined a dbfile
I have a Model which has some constants defined, like below: class Order(models.Model): WAITING
I have a model which has a certain behaviour implemented. class X { ....
I have a model called Contact which has_one guest like so. class Contact <
I have a model containing ImageField which should be resized after uploading. class SomeModel(models.Model):
In my model, I have a base object class A which holds a set

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.