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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:17:25+00:00 2026-05-14T06:17:25+00:00

I’m trying to create a widget within the module and then load that widget

  • 0

I’m trying to create a widget within the module and then load that widget from ‘outside’ of the module. More particularly I’m using user module written by someone else. I don’t want to have a separate page for displaying a login form, therefore I tried to make a CPortlet/widget (confusion) displaying the login form. Basically, I’ve moved the code from LoginController into that widget. Then I try to display the widget on some random page by

<?php $this->widget('user.components.LoginForm'); ?>

However, I get an error

CWebApplication does not have a method named "encrypting".

in UserIdentity class in this line:

else if(Yii::app()->controller->module->encrypting($this->password)!==$user->password)

This happens, because I’m basically trying to execute this code within context of the app and not the module. Thus the “Yii::app()->controller->module” trick doesn’t really work as expected.

  1. What am I doing wrong:-\
  2. Is there a better way to achieve this. I.e. display that login form in some other page, which is normally displayed by accessing login controller within user module (user/login) or is a widget the right way of doing it?

Thanks.

  • 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-05-14T06:17:25+00:00Added an answer on May 14, 2026 at 6:17 am

    The quick solution

    Ok, so I simply ended up doing

    Yii::app()->getModule('user')->encrypting($this->password)
    

    instead of

    Yii::app()->controller->module->encrypting($this->password)
    

    Notice that now the module must be called ‘user’ in the main config, but I think this allows for more flexibility. I.e. we’re not bound to only use module functionality within the module.

    Additional insight on displaying widget outside of the module scope

    After playing more with it that’s what I did. In the UserModule.php I’ve created a method

    public static function id() {
        return 'user';
    }
    

    Then everywhere where I need the module I use

    Yii::app()->getModule(UserModule::id())->encrypting($this->password)
    

    I don’t like having many imports related to the module like:

    'application.modules.user.models.*',
    'application.modules.user.components.*',
    

    Because we already have those imports in the UserModule.php:

    public function init()
    {
        // this method is called when the module is being created
        // you may place code here to customize the module or the application
    
        // import the module-level models and components
        $this->setImport(array(
            'user.models.*',
            'user.components.*',
        ));
    }
    

    Therefore whenever you know that some piece of functionality will be used outside of the module it’s important to make sure the module is loaded. For example, in the LoginForm widget that I am trying to display NOT in one of the module controllers, I have this line of code:

    $model = new UserLogin;
    

    However, UserLogin is a model inside of the User module, and in order to be able to autoload this model we first have to make sure the module was initialised:

    $module = Yii::app()->getModule(UserModule::id());
    $model = new UserLogin;
    

    I hope this will be helpful if you were stuck with the whole modules concept the way I was.
    http://www.yiiframework.com/forum/index.php?/topic/6449-access-another-modules-model/ was useful but hard to find =)

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
I am trying to loop through a bunch of documents I have to put
I have a bunch of posts stored in text files formatted in yaml/textile (from

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.