[SOLVED]how to create a widget


how to create a widget out of an existing login action view ?

this is what I currently have in my login.php view file of the site’s controller actinLogin()

<div id="login-wrapper">

    <div class="login-container">

        <?php $form=$this->beginWidget('CActiveForm', array('id'=>'login-form','enableAjaxValidation'=>true,)); ?>

                <div class="login-input">


                    <?php echo $form->labelEx($model,'username'); ?>

                    <?php echo $form->textField($model,'username',array('placeholder'=>'username')); ?>



                    <?php echo $form->labelEx($model,'password'); ?>

                    <?php echo $form->passwordField($model,'password',array('placeholder'=>'password')); ?>


                <div id="bmenu">

                    <ul class="menu">

                        <li class="register"><?php echo CHtml::link("Registration", array('wsmembers/register'));?></li>

                        <li class="login"><?php echo CHtml::submitButton('Login',array('id'=>'login_button')); ?></li>




         <?php $this->endWidget(); ?>

    </div><!-- .login-container -->

    <div class="login-bg-bottom"></div>

</div><!-- #login-wrapper -->

if I click the default login link from the navbar, that’s the only time that code above shows

the login box at the upper right corner of the page

but the problem is, the login box should be at the homepage and must already be there

without clicking a login link at the navbar. so how am i gonna do that? this have something to do with main.php layout file right?

this example is not enough


or this


or even this


some related examples would be a great help, T.I.A

problem solved,

I created a file at the components folder

e.g Login.php

and then I created a "views" folder inside the components folder

then I created a file named,

e.g login.php

which contains the login html codes

then the Login.php class contains

class Login extends CWidget


   public function init()


     //left blank


   public function run()


     //some site controller logic here



at the main.php layout file I placed this

$this->widget('application.components.Login', array());

note: don’t forget to use the keyword “$this” inside the run() ;D

hope that helps anyone who’ll encounter this in the future :D


excellent i love the brief tutorial.