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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:47:30+00:00 2026-06-09T08:47:30+00:00

I have written a component as below. class GoogleApiComponent extends Component { function __construct($approval_prompt)

  • 0

I have written a component as below.

class GoogleApiComponent extends Component {
    function __construct($approval_prompt) {
        $this->client = new apiClient();
        $this->client->setApprovalPrompt(Configure::read('approvalPrompt'));
    }
}

I am calling this in $components variable of AppController.
Then I have written UsersController as below.

class UsersController extends AppController {
    public function oauth_call_back() {

    }
}

So in oauth_call_back action I wanna create object of GoogleApiComponent and also call the constructor with parameter.
How to do it in CakePHP 2.1?

  • 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-09T08:47:35+00:00Added an answer on June 9, 2026 at 8:47 am

    You can pass the Configure::read() value as a setting property,
    or put the constructor logic within the initialize() method of your component.

    class MyComponent extends Component
    {
        private $client;
    
        public function __construct (ComponentCollection $collection, $settings = array())
        {
            parent::__construct($collection, $settings);
            $this->client = new apiClient();
            $this->client->setApprovalPrompt ($settings['approval']);
        }
    }
    

    And then write this in your UsersController:

    public $components = array (
        'My'    => array (
            'approval' => Configure::read('approvalPrompt');
        )
    );
    

    Or you may write your component as such:

    class MyComponent extends Component
    {
        private $client;
    
        public function __construct (ComponentCollection $collection, $settings = array())
        {
            parent::__construct($collection, $settings);
            $this->client = new apiClient();
        }
    
        public function initialize()
        {
            $this->client->setApprovalPrompt (Configure::read('approvalPrompt'));
        }
    }
    

    I would recommend you to have a look at the Component class, which is within CORE/lib/Controller/Component.php. You’d be surprised of what you’ll learn when you read the source code.

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

Sidebar

Related Questions

I have written this code: class component(object): def __init__(self, name = None, height =
I have a COM component written in C# that makes calls to ConfigurationManager.AppSettings.Get(...). This
have written this little class, which generates a UUID every time an object of
I have written a default table render as follows: public class CustTableRenderer extends DefaultTableCellRenderer{
I have written a new custom component derived from TLabel. The component adds some
I have written a custom component for jsf. The renderer extends com.sun.faces.renderkit.html_basic.ListboxRenderer. My component
I have a component written in C++ and I want to share an H
I have written an advanced text editor component (fixed-width, syntax highlighting, etc.) in Delphi,
I have written xml file which contains html tags as element like <component> <input
I have a third party component written in C/C++ (on VS 2010) which can

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.