Example For Creating New Widget Extension

Hai everyone,

I have tried to create new widget as extension that extends the CWidget as per the guidelines in the framework forum. http://www.yiiframework.com/doc/guide/1.1/en/extension.create

this is my extension folder structure










and i have use this extension in one of my view as

<?php echo $this->widget('application.extensions.widget.login.Login');

I dont know its throughing some error like

Alias "application.extensions.widget.login.Login" is invalid. Make sure it points to an existing PHP file and the file is readable.

how can i solve this…?

What else i have to do?

What are the thing i have missed?

and i dont know where to put the

 <?php $this->render(''); ?> 

guide me…

Sorry it may be a silly thing…




Please see it…

1)create a new widgets


2)create a new extesion…


i hope it’s some help…

Thanks Modi,

I read the tutorials and created my Widget in extension folder.

the following thinks i have done.

Create a widget view in extensions/widget/login/views/hloginForm.php with this codes

<?php echo CHtml::beginForm($this->url, 'post', $this->htmlOptions); ?>

<div class="form header">




			<div class="row">

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

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

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


			<div class="row rememberMe">

				<?php echo $form->checkBox($model,'rememberMe'); ?>

				<?php echo $form->label($model,'rememberMe',array('class'=>'dull')); ?>

				<?php echo $form->error($model,'rememberMe'); ?>




			<div class="row">

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

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

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



			<div class="row">

				<?php echo $form->label($model,'Forget Password?',array('class'=>'dull')); ?>




			<div class="row"> &nbsp; </div>

			<div class="row">

				<?php echo CHtml::submitButton('Login',array('class'=>'logbtn')); ?>





</div><!-- form -->

<?php  echo CHtml::endForm(); ?>

and created a Login.php in main widget folder

(that is : application/extensions/widget/login/login.php) with the code like :


class Login extends CWidget


	public function run()






and made all extensions as autoload in config/main.php






then try to use it in my webpage view file as

<?php $this->widget('Login'); ?>

this throw me this error

Tell me whats Wrong??? What should i do to get my Widget in my page.

and once i tried this

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

i got this error


you can create the new folder widgets on application root folder not in extension folder (application/widgets/login/login.php)

please try it…


If i make it as an extension so that i can reuse it… that’s why i have included in there.

what seems to be wrong in my code… or What i am missing?

i think you may change the


and get a folder permission issue on extesion folder so please first you can set the folder permission on full project

please try it…

Thanks for your time Modi,

My extension is now working fine… but when i try to use HTML form elements in to that widget it won’t work… What should i do for that?


I want to add a login form in my extended widget… i have designed the form and its model. where i have to put the model file in my extension folder… like want to create new folder as models and place the file? Is it correct or not? Any one please clear this simple doubt.



Yes you can put the model file on models folder not any issue.

Thanks modi… Will try now!!!

or if you want to disply the htnml tag on widgets file you can use Heredoc PHP function.

please see it//


i hope it’s some help.

When i try to put the model file in models directory i got this error.