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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:41:37+00:00 2026-06-16T04:41:37+00:00

I am new to Yii framework. I have a form with three fields. I

  • 0

I am new to Yii framework.

I have a form with three fields. I need one of those be a select drop down element that its data comes from previously added data which are in mysql table.

How can I do it ?

  • 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-16T04:41:38+00:00Added an answer on June 16, 2026 at 4:41 am

    If you have a model set up for the table that contains the data you want to use in your dropdown list you can use the CHtml::dropDownList() method the render a dropdown list, and CHtml::listData() to render that model into items for the list, for example;

    echo CHtml::dropDownList(
        'attribute_name',
        '',
        CHtml::listData(MyOtherModel::model()->findAll(),'id','name')
    );
    

    I use Gii a lot, which uses CActiveForm widget to display forms, if your form uses CActiveForm too you could render your dropdown something like;

    $form=$this->beginWidget('CActiveForm', array(
        'action'=>Yii::app()->createUrl($this->route),
        'method'=>'get',
    ));
    
    ...
    
    echo $form->label($model,'attribute_name');
    echo $form->dropDownList(
        $model,
        'attribute_name',
        CHtml::listData(MyOtherModel::model()->findAll(),'id','name')
    );
    
    ...
    
    $this->endWidget();
    

    Note that CActiveForm uses CHtml::activeDropDownList() rather than CHtml::dropDownList() that I used in my first example, hence the slight difference in syntax between my two examples.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a drop down list (yii framework) , that i would like to
I am using a script that runs on the YII framework... I have this
I am the new user of Yii Framework , Now I have created a
I have a view that calls the Yii Framework CDetailView as follows: <?php $model
I am new to Yii framework and i need to define a function which
I'm new to Yii framework, I need an FCK editor for my CMS management
I am new to php and the yii framework. I have started developing simple
I'm new using Yii framework. I show a list a checkbox. But it's not
Possible Duplicate: Yii CHtml::radioButtonList - CSS to align horizontally Am new to yii framework
I'm building a web application using Yii framework, and i'm quite new to it.

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.