Yii Framework Forum: How to create dropdown list box - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How to create dropdown list box

#1 User is offline   Bapi Roy 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 02-February 12
  • Location:Alipurduar, India

Posted 10 May 2012 - 06:15 AM

I have two table branch and other state. Branch table has state_id link with state table by state_id.

Two model are created for both tables. Now I want to create a dropdown list box with all state anem present in State table thru Branch model to display it in a form.
Bapi Roy
0

#2 User is offline   Pravin Gajera 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 137
  • Joined: 25-October 11
  • Location:India

Posted 10 May 2012 - 06:20 AM

Hi

use

$list = CHtml::listData($models,'State_id', 'State_name');


echo CHtml::dropDownList('state', $models->state_id, $list, array('empty' => '(Select a state'));

Thanks
2

#3 User is offline   Bapi Roy 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 02-February 12
  • Location:Alipurduar, India

Posted 11 May 2012 - 04:00 AM

@ Pravin Gajera
Thanks for your reply.

I still have problem in getting data through "$list = CHtml::listData($models,'State_id', 'State_name');". It is returning empty array
Bapi Roy
0

#4 User is offline   shailesh 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 79
  • Joined: 14-May 11
  • Location:Ahmedabad(India)

Posted 12 May 2012 - 12:22 AM

In View For Our Form Just

Instead Of textField Just Write

echo CHtml::dropDownList('state', $models->state_id,array_merge($list, array('empty' => '(Select a state')));
0

#5 User is offline   Bapi Roy 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 02-February 12
  • Location:Alipurduar, India

Posted 12 May 2012 - 02:14 AM

$list=CHtml::listData(SysState::model()->findAll(), 'state_id', 'state_name'); fixed my problem.
Bapi Roy
0

#6 User is offline   shantanu 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 11-September 12

Posted 05 October 2012 - 01:14 AM

View PostBapi Roy, on 12 May 2012 - 02:14 AM, said:

$list=CHtml::listData(SysState::model()->findAll(), 'state_id', 'state_name'); fixed my problem.


this works.. Thanks!
0

#7 User is offline   SUBHASH 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 08-November 12

Posted 08 November 2012 - 01:51 AM

I am new to this yii framework and Now i am working on the login page i stored the username and password in the login table and i want to retrieve these values in authenticate() which is present UserIdentity.php

my table name is login with two columns username password
my Model name is LoginForm.php

and

my register model name is Register.php
through this i stored the values into the database

my code in authentication() is
public function authenticate()
{
$username = strtolower($this->username);
$password = $this->password;
$user = Register::model()->find('username=:username and password=:password',
array(
':username'=>$username,
':password'=>$password,
));

if ($user === null)
$this->errorCode = self::ERROR_USERNAME_INVALID;
else
return $this->errorCode == self::ERROR_NONE;
}

so please help me in retrieving these values correctly.
0

#8 User is offline   Saqib 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 14-November 12

Posted 26 November 2012 - 03:04 AM

View PostSUBHASH, on 08 November 2012 - 01:51 AM, said:

I am new to this yii framework and Now i am working on the login page i stored the username and password in the login table and i want to retrieve these values in authenticate() which is present UserIdentity.php

my table name is login with two columns username password
my Model name is LoginForm.php

and

my register model name is Register.php
through this i stored the values into the database

my code in authentication() is
public function authenticate()
{
$username = strtolower($this->username);
$password = $this->password;
$user = Register::model()->find('username=:username and password=:password',
array(
':username'=>$username,
':password'=>$password,
));

if ($user === null)
$this->errorCode = self::ERROR_USERNAME_INVALID;
else
return $this->errorCode == self::ERROR_NONE;
}

so please help me in retrieving these values correctly.




Try this :

class UserIdentity extends CUserIdentity
{

public $_id;


public function authenticate()
{
$username=strtolower($this->username);
$user=Register::model()->find('LOWER(username)=?',array($username));
if($user===null)
$this->errorCode=self::ERROR_USERNAME_INVALID;
else if(!$user->validatePassword($this->password))
$this->errorCode=self::ERROR_PASSWORD_INVALID;
else
{
$this->_id=$user->id;

$this->username=$user->username;
$this->errorCode=self::ERROR_NONE;
}
return $this->errorCode==self::ERROR_NONE;
}


public function getId()
{
return $this->_id;
}
}
0

#9 User is offline   Mohamed Habeeb 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 26-July 12
  • Location:Trichy, Tamil Nadu, India

Posted 05 December 2012 - 02:21 AM

<?php echo $form->dropDownList($addr,'cou_id', CHtml::listData(AccAccount::model()->findAll('cou_id'), 'cou_id', 'cou_name'), array('empty'=>'--none--')) ?>
0

#10 User is offline   walkman2508 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 21-June 14

Posted 23 June 2014 - 02:43 AM

hi
i want to give link in dropdown is it possible...???
i want to check email id already present in table if it is
already present then by clicking on email id i have to goto the profile whose email id is present...
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

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