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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:03:32+00:00 2026-06-16T05:03:32+00:00

I want list all objects of my model, and write to file the id

  • 0

I want list all objects of my model, and write to file the id of selected model. Using SiteController I render my page but what model I shall use?

$models = myModel::model()->findAll();
$list = CHtml::listData($models, 'id', 'name');

echo CHtml::dropDownList( ???? , $select, $list);
  • 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-16T05:03:33+00:00Added an answer on June 16, 2026 at 5:03 am

    If I get what you’re trying to do, You’re talking about two models. Like tbl_product => Product and tbl_category => Category.

    For demonstration purpose: Say, you want to create a new product and every product must belong to a category, then you might make use of the active dropdown. Using code similar to yours, you can say:

    $category = Category::model()->findAll();
    $list = CHtml::listData($category, 'id', 'name');
    

    An important thing to note is that CHtml::activeDropDownList() expects different kinds of arguments. The main difference between it and CHtml::dropDownList() is that activeDropDownList( is tied to a Model while dropDownList() isn’t.

    public static string activeDropDownList(CModel $model, string $attribute, array $data, array $htmlOptions=array ())
    
    public static string dropDownList(string $name, string $select, array $data, array $htmlOptions=array ())
    

    So, using the example, assuming our Product model has a field called category_id, then the dropdown list would be generated using either:

    CHtml::activeDropDownList($model, 'category_id', $list);
    

    or if you’ve created an Activeform object like this:

    $form=$this->beginWidget('CActiveForm');
    

    then you could create the dropDown list like this:

    $form->dropDownList($model, 'category_id', $list);
    

    Where $model would be the Product model.

    I hope this has been helpful.

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

Sidebar

Related Questions

I want to execute a function on all the objects within a List of
I have a list of objects and I want to remove all the ones
I want list to all the indesign file in my external HD, I tried
I want to list all files in a directory Using PyroCMS. Using the Files
I want to list all files on an FTP server using PHP. According to
I want to write an Extbase Backend module which needs a list of all
How can I get a list of all the model objects that have a
I retrieve a list of ObjectId and I want to retrieve all object in
i am trying to build a statics system i want list all pages in
I want to list all .xml files in a dir and its subdir. I

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.