Yii Framework Forum: How to add drop-down country list in yii-user Profile field - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

How to add drop-down country list in yii-user Profile field How to add drop-down country list in yii-user Profile field Rate Topic: -----

#1 User is offline   maverick 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 02-November 10

Posted 02 November 2010 - 07:37 PM

Hello everyone !

I am new to Yii and frankly new to Object oriented php also. I am trying to learn this. Just needed some help.

I am using the yii-user extension and I can add profile fields using that. I need a add a profile field to create a drop-down list of countries or states.

I think i need to create a widget for that, since I'm new, I don't know what to do ??

Please if anyone could help me with this...
1

#2 User is offline   jeewendra_kumar 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 25-October 10

Posted 03 November 2010 - 01:38 AM

View Postmaverick, on 02 November 2010 - 07:37 PM, said:

Hello everyone !

I am new to Yii and frankly new to Object oriented php also. I am trying to learn this. Just needed some help.

I am using the yii-user extension and I can add profile fields using that. I need a add a profile field to create a drop-down list of countries or states.

I think i need to create a widget for that, since I'm new, I don't know what to do ??

Please if anyone could help me with this...



hi i am newbie......i have done the same thing with a tbl_state,tbl_country

you can use this better you generate CRUD for state & Country.so, that you can edit any state or country later.

in _form file add following code

<div>
<?php echo $form->labelEx($model, 'state'); ?>
<?php echo CHtml::activeDropDownList($model, 'state_id',State::model()->getStateOptions()); ?>
<?php echo $form->error($model, 'state'); ?>
</div>

and in state model add a function

public function getStateOptions() {
array('primaryKey' => 'displayData');
}

best wishes
0

#3 User is offline   Callum 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 04-April 11

Posted 05 April 2011 - 05:31 AM

There's an easy way to do this. Create a profile field called whatever you like and in the Range box, put a list of country separated by semi-colons. It will automatically be converted to a drop down list. Mine looks like this:
United Kingdom;Australia;Canada;New Zealand;United States;Afghanistan;Albania;Algeria;Andorra;Angola;Antigua & Deps;Argentina;Armenia;Austria;Azerbaijan;Bahamas;Bahrain;Bangladesh;Barbados;Belarus;Belgium;Belize;Benin;Bhutan;Bolivia;Bosnia Herzegovina;Botswana;Brazil;Brunei;Bulgaria;Burkina;Burundi;Cambodia;Cameroon;Cape Verde;Central African Rep;Chad;Chile;China;Colombia;Comoros;Congo;Congo {Democratic Rep};Costa Rica;Croatia;Cuba;Cyprus;Czech Republic;Denmark;Djibouti;Dominica;Dominican Republic;East Timor;Ecuador;Egypt;El Salvador;Equatorial Guinea;Eritrea;Estonia;Ethiopia;Fiji;Finland;France;Gabon;Gambia;Georgia;Germany;Ghana;Greece;Grenada;Guatemala;Guinea;Guinea-Bissau;Guyana;Haiti;Honduras;Hungary;Iceland;India;Indonesia;Iran;Iraq;Ireland {Republic};Israel;Italy;Ivory Coast;Jamaica;Japan;Jordan;Kazakhstan;Kenya;Kiribati;Korea North;Korea South;Kosovo;Kuwait;Kyrgyzstan;Laos;Latvia;Lebanon;Lesotho;Liberia;Libya;Liechtenstein;Lithuania;Luxembourg;Macedonia;Madagascar;Malawi;Malaysia;Maldives;Mali;Malta;Marshall Islands;Mauritania;Mauritius;Mexico;Micronesia;Moldova;Monaco;Mongolia;Montenegro;Morocco;Mozambique;Myanmar, {Burma};Namibia;Nauru;Nepal;Netherlands;Nicaragua;Niger;Nigeria;Norway;Oman;Pakistan;Palau;Panama;Papua New Guinea;Paraguay;Peru;Philippines;Poland;Portugal;Qatar;Romania;Russian Federation;Rwanda;St Kitts & Nevis;St Lucia;Saint Vincent & the Grenadines;Samoa;San Marino;Sao Tome & Principe;Saudi Arabia;Senegal;Serbia;Seychelles;Sierra Leone;Singapore;Slovakia;Slovenia;Solomon Islands;Somalia;South Africa;Spain;Sri Lanka;Sudan;Suriname;Swaziland;Sweden;Switzerland;Syria;Taiwan;Tajikistan;Tanzania;Thailand;Togo;Tonga;Trinidad & Tobago;Tunisia;Turkey;Turkmenistan;Tuvalu;Uganda;Ukraine;United Arab Emirates;Uruguay;Uzbekistan;Vanuatu;Vatican City;Venezuela;Vietnam;Yemen;Zambia;Zimbabwe


I prioritised the countries most likely to be useful to us. I got the data here[1] and used gedit to replace newlines with semi-colons. Easy as pie. :-)

[1] I'm a new user so I can't post links, add http to the front of this for the list: openconcept.ca/blog/mgifford/text_list_all_countries

Update: Ok, turns out the range value is limited to 255 characters. There is a simple solution for that, simply modify the tbl_profile_fields table, change the row range from a VARCHAR(255) to a TEXT. You can do this in phpMyAdmin or on the command line through mysql with a query like:
ALTER TABLE `tbl_profiles_fields` CHANGE `range` `range` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL

Love & joy - Callum.
1

#4 User is offline   Gbenga Sodunke 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 30-September 14

Posted 11 November 2014 - 02:25 AM

Hello Callum

Thanks for your response here. My question is, how will it be automatically converted to a drop down list? How can I use the list of countries saved in the table as a drop down list in my view files?


Thanks.
0

#5 User is offline   Rohit Suthar 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 247
  • Joined: 12-May 14
  • Location:Mumbai, India

Posted 12 November 2014 - 03:02 AM

View Postmaverick, on 02 November 2010 - 07:37 PM, said:

Hello everyone !

I am new to Yii and frankly new to Object oriented php also. I am trying to learn this. Just needed some help.

I am using the yii-user extension and I can add profile fields using that. I need a add a profile field to create a drop-down list of countries or states.

I think i need to create a widget for that, since I'm new, I don't know what to do ??

Please if anyone could help me with this...



All the solution at single place, try this wiki -

http://www.yiiframew...y-example-chtml
Thanks & regards,

ROHIT SUTHAR
Mumbai(India)

Follow me - @rohisuthar

yii.at

If you found your solutions.... Don't hesitate to click on '+1' button
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users