Accessing other model

I downloaded the extension yii-user and placed it under modules in my website. My website currently contains a few modules one of wich is called landingpage.

I want to use the login and registration provided by the yii-user extension. Since I’m not that familiar with the yii framework yet I basically have no idea how to implement it in my current website.

The extension is installed and works, but as a standalone section, and not implemented in the current landingpage.

Basically what I want to do is include the login.php into the index.php of the landingpage.

Is such a thing possible?

Would a redirect to the login page be possible? If not you can try overriding the actions() method to specify that the action ‘login’ in the landing page module/controller should be loaded from the ‘user/login’ controller.

What I do now is basically this in the layout file:




<body>

<? $this->renderPartial('/_partials/header'); ?>

<? $this->renderPartial('/_partials/login'); ?>

<?= $content; ?>

<? $this->renderPartial('/_partials/footer'); ?>

</body>



The login is always on the website, once logged in something else will be displayed where the login form once was.

So redirecting to the user/login isn’t possible as far as I know.

As for overriding the actions() method so that is loads from the user/login module, I have no idea how to do that as my expierence with Yii is very basic atm, only started using it 1 week ago.

if your using the CWebUser you can use the isGuest property to determine if the member is logged in or not. The code in your layout will need to be changed accordingly. But since i am not sure what you trying to do i would just display a link to get more details about the Actions feature inside a controller which i hope will be the thing you are looking for:

http://www.yiiframework.com/doc/guide/basics.controller#action

Maybe my english isn’t that great, I’ll try to explain myself a little better:

What I have atm are 2 modules, 1 is called landingpage which will be used for mobile devices and the other module is called user which comes from the extension found [url=http://www.yiiframework.com/extension/yii-user/]here/url.

In order to access the landingpage people have to log in, this is where the user module comes in play. I don’t want the user module included in the landingpage because in the future there will be a third module, a normal website. That website will also require a login and with a username and password you’ll be able to access both sites.

so the layout file of the landingpage looks as follows:




<body>

  <? $this->renderPartial('/_partials/header'); ?>

  <? $this->renderPartial('/_partials/login'); ?>

  <?= $content; ?>

  <? $this->renderPartial('/_partials/footer'); ?>

</body>



The header and footer files are just basic files with logo’s etc.

The $content will render the content of the website as usual.

And the login will render the login form on the website, at least that’s the idea. The problem is that the login form I want is in the user module. and I can’t seem to access it from within the landingpage module. My idea was to simple include the login.php from the user module, but that’s not possible because then you’ll miss controllers etc.

So actually I want to render the login.php from the user module within the landingpage module.

And yeah the idea is to later on use the isGuest() to hide to login form and show messages instead.

I hope I made it more clear what I want to do and you got an idea what I try to achieve.

I assume the login.php your referring is a view file, It it’s located under the Yii-user module then you will need to render it by specifying the full path to that file (or maybe try dot syntax it might work) in order to include that in your controller.

Even if you do succeed in embedding the view file inside your controller that doesn’t mean you will be able to include the entire login controller login as well. So it’s either you will dynamically create the Login controller in your landing page controller by calling CWebApplication::createController() (

http://www.yiiframework.com/doc/api/CWebApplication#createController-detail) which i am not really sure if it’s a good approach or event possible and WILL solve your problem, I doubt but you should try. It will basically load the controller and will return the controller instance so you could use that instance for rendering the view and the view will be able to read the right controller instance (which will be the login controller instance and not your controller instance).

Resolve View file: http://www.yiiframework.com/doc/api/CController#getViewFile-detail

Thanks for your help, gonna give it a shot. Will let you know once I’ve figured it all out :)