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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:06:40+00:00 2026-06-04T13:06:40+00:00

$this->widget(‘zii.widgets.jui.CJuiAutoComplete’, array( ‘name’=>’test1’, ‘value’=>’test21’, ‘source’=>$this->createUrl(‘jui/autocompleteTest’), // additional javascript options for the autocomplete plugin ‘options’=>array(

  • 0
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'name'=>'test1',
'value'=>'test21',
'source'=>$this->createUrl('jui/autocompleteTest'),
// additional javascript options for the autocomplete plugin
'options'=>array(
        'showAnim'=>'fold',
),
));

I am new to Yii framework.

i am working on autocomplete but not able to understand the code given above, what does createUrl mean?

do we need to create a page by User or that line itself creates that?

Please help me on this.

Here’s the complete Reference code

$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
//'model'=>$model,
//'attribute'=>'name',
'id'=>'country-chain',
'name'=>'country_chain',
'source'=>$this->createUrl('request/suggestCountry'),
'options'=>array(
    'delay'=>300,
    'minLength'=>2,
    'showAnim'=>'fold',
    'select'=>"js:function(event, ui) {
        $('#label').val(ui.item.label);
        $('#code').val(ui.item.code);
        $('#call_code').val(ui.item.call_code);
    }"
),
'htmlOptions'=>array(
    'size'=>'40'
),
));

Source: the above code Live Example

What i need to know is where to add model name and where to add Database Field Name


my model name is

detail
,in this the fields are:

  • id , name , email , mobile

i want Name under autocomplete – email and mobile should come like as the above example

Thanks in Advance
Devendar

enter image description here

Sorry Friend,

Here goes the the structure

Model Name : Details

controller name is – DetailsController

Under Views > details > _form.php

    <div class="form"> <?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'details-form',
'enableAjaxValidation'=>false,)); ?>

<p class="note">Fields with <span class="required">*</span> are required.</p>

<?php echo $form->errorSummary($model); ?>

<div class="row">
    <?php echo $form->labelEx($model,'id'); ?>


    <?php echo $form->textField($model,'id'); ?>
    <?php echo $form->error($model,'id'); ?>
</div>

<div class="row">
    <?php echo $form->labelEx($model,'name'); ?>
    <?php $this->widget('CAutoComplete',
      array(
                     //name of the html field that will be generated
         'name'=>'name', 
                   //replace controller/action with real ids
         'url'=>array('DetailsController/AutoCompleteLookup'), 
         'max'=>10, //specifies the max number of items to display

                     //specifies the number of chars that must be entered 
                     //before autocomplete initiates a lookup

         ));    ?>
            <?php echo $form->error($model,'name'); ?>
</div>

<div class="row">
    <?php echo $form->labelEx($model,'phone'); ?>
    <?php echo $form->textField($model,'phone'); ?>
    <?php echo $form->error($model,'phone'); ?>
</div>

<div class="row">
    <?php echo $form->labelEx($model,'email'); ?>
    <?php echo $form->textField($model,'email'); ?>
    <?php echo $form->error($model,'email'); ?>
</div>

<div class="row buttons">
    <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div><?php $this->endWidget(); ?> </div><!-- form -->

Controller Code is

<?php  class DetailsController extends Controller { /**
 * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
 * using two-column layout. See 'protected/views/layouts/column2.php'.
 */
public $layout='//layouts/column2';

/**
 * @return array action filters
 */
public function filters()
{
    return array(
        'accessControl', // perform access control for CRUD operations
    );
}

public function actionAutoCompleteLookup()
    {
       if(Yii::app()->request->isAjaxRequest && isset($_GET['q']))
       {

          $name = $_GET['q']; 

          $criteria = new CDbCriteria;
          $criteria->condition = "name LIKE :sterm";
          $criteria->params = array(":sterm"=>"%$name%");

          $userArray = User::model()->findAll($criteria);
          $returnVal = '';
          foreach($userArray as $userAccount)
          {
             $returnVal .= $userAccount->getAttribute('name').'|'
                                         .$userAccount->getAttribute('id')."\n";
          }
          echo $returnVal;
       }
    }

/**
 * Specifies the access control rules.
 * This method is used by the 'accessControl' filter.
 * @return array access control rules
 */
public function accessRules()
{
    return array(
        array('allow',  // allow all users to perform 'index' and 'view' actions
            'actions'=>array('index','view'),
            'users'=>array('*'),
        ),
        array('allow', // allow authenticated user to perform 'create' and 'update' actions
            'actions'=>array('create','update'),
            'users'=>array('@'),
        ),
        array('allow', // allow admin user to perform 'admin' and 'delete' actions
            'actions'=>array('admin','delete'),
            'users'=>array('admin'),
        ),
        array('deny',  // deny all users
            'users'=>array('*'),
        ),
    );
}

/**
 * Displays a particular model.
 * @param integer $id the ID of the model to be displayed
 */
public function actionView($id)
{
    $this->render('view',array(
        'model'=>$this->loadModel($id),
    ));
}

/**
 * Creates a new model.
 * If creation is successful, the browser will be redirected to the 'view' page.
 */
public function actionCreate()
{
    $model=new Details;

    // Uncomment the following line if AJAX validation is needed
    // $this->performAjaxValidation($model);

    if(isset($_POST['Details']))
    {
        $model->attributes=$_POST['Details'];
        if($model->save())
            $this->redirect(array('view','id'=>$model->id1));
    }

    $this->render('create',array(
        'model'=>$model,
    ));
}

/**
 * Updates a particular model.
 * If update is successful, the browser will be redirected to the 'view' page.
 * @param integer $id the ID of the model to be updated
 */
public function actionUpdate($id)
{
    $model=$this->loadModel($id);

    // Uncomment the following line if AJAX validation is needed
    // $this->performAjaxValidation($model);

    if(isset($_POST['Details']))
    {
        $model->attributes=$_POST['Details'];
        if($model->save())
            $this->redirect(array('view','id'=>$model->id1));
    }

    $this->render('update',array(
        'model'=>$model,
    ));
}

/**
 * Deletes a particular model.
 * If deletion is successful, the browser will be redirected to the 'admin' page.
 * @param integer $id the ID of the model to be deleted
 */
public function actionDelete($id)
{
    if(Yii::app()->request->isPostRequest)
    {
        // we only allow deletion via POST request
        $this->loadModel($id)->delete();

        // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
        if(!isset($_GET['ajax']))
            $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
    }
    else
        throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
}

/**
 * Lists all models.
 */
public function actionIndex()
{
    $dataProvider=new CActiveDataProvider('Details');
    $this->render('index',array(
        'dataProvider'=>$dataProvider,
    ));
}

/**
 * Manages all models.
 */
public function actionAdmin()
{
    $model=new Details('search');
    $model->unsetAttributes();  // clear any default values
    if(isset($_GET['Details']))
        $model->attributes=$_GET['Details'];

    $this->render('admin',array(
        'model'=>$model,
    ));
}

/**
 * Returns the data model based on the primary key given in the GET variable.
 * If the data model is not found, an HTTP exception will be raised.
 * @param integer the ID of the model to be loaded
 */
public function loadModel($id)
{
    $model=Details::model()->findByPk($id);
    if($model===null)
        throw new CHttpException(404,'The requested page does not exist.');
    return $model;
}



/**
 * Performs the AJAX validation.
 * @param CModel the model to be validated
 */
protected function performAjaxValidation($model)
{
    if(isset($_POST['ajax']) && $_POST['ajax']==='details-form')
    {
        echo CActiveForm::validate($model);
        Yii::app()->end();
    }
}

}

i tried the above code – mot found any result please help me friend

Thanks
Devendar

  • 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-06-04T13:06:41+00:00Added an answer on June 4, 2026 at 1:06 pm

    see this link..

    http://www.yiiframework.com/wiki/25/using-cautocomplete-to-display-one-value-and-submit-another/

    implement the code according to this link…autocomplete will work fine..

    OR

    $this->widget('zii.widgets.jui.CJuiAutoComplete', array(
    'name'=>'test1',
    'value'=>'test21',
    'source'=>$this->createUrl('Your Contoller Name / your function Name'),
    // additional javascript options for the autocomplete plugin
    'options'=>array(
            'showAnim'=>'fold',
    ),
    ));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this widget: $this->setWidget('slug', new sfWidgetFormDoctrineChoice(array('model' => 'MyTable', 'method' => 'myMethod', 'key_method' =>
I want to know what is the name of this widget , and how
I'm looking for this widget name so I can look for existing implementations. I
I'm trying to do a query like this: Widget.find(:all, :conditions => [name like %awesome%])
I am trying to find the java class name for this widget. It looks
I love this widget in google closure, Zippy and I need an equevalent in
I have a JavaScript widget that is hosted on websites. This widget tracks state
I am working on a home screen widget. I hope this widget can support
I am writing a web page widget for my company. This widget must inject
I did mockups in balsamiq & they have this nice widget, which Allowed to

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.