Creating widget as an extension in Yii

1.1k views Asked by At

I am very new to YII and its extensions... i am trying to create the basic login widget as an extension so that i can reuse it....

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">
<table>
    <tr> 
            <td>
                    <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>
                    <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>
            </td>
            <td>
                    <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>

                    <div class="row">
                            <?php echo $form->label($model,'Forget Password?',array('class'=>'dull')); ?>
                    </div>
            </td>
            <td>
                    <div class="row"> &nbsp; </div>
                    <div class="row">
                            <?php echo CHtml::submitButton('Login',array('class'=>'logbtn')); ?>
                    </div>
            </td>
    </tr>
</table>

and created a Login.php in main widget folder (that is : application/extensions/widget/login/login.php) with the code like :

<?php 
class Login extends CWidget
{
    public function run()
    {
            $this->render('hloginForm');
    }
}
?>

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

as

    'import'=>array(
            ...
            'application.extensions.*',
    ),

then try to use it in my webpage view file as

widget('Login'); ?>

this throw me this error

Quote

include(Login.php) [function.include]: failed to open >stream: No such file or directory

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

Quote

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

1

There are 1 answers

0
Jothi Sankar N Kanakavel On BEST ANSWER

Changing the Access permission for the extension folder fixes the problem. After that it works fine as expected.