开发者

how to render 216,912 rows of city data without hanging in Yii?

I am having a problem with a city dropdown menu. the situation is like this, I have 3 tables. namely countries, states, cities, I was able to generate a dropdown menu for Countries, States.. I was able to generate a dropdown menu for Cities also but, the problem is, when I pushed the code to production server, the page turned white due to too much memory consumption, here's my code

//model
    public function fetchCityName()
    {
        $connection = Yii::app()->db->createCommand("SELECT CityName from gg_t_worldareascities ORDER BY CityName ASC")->queryColumn();
        return $connection;

    }

//view
        <?php 
            $this->widget('CAutoComplete', array(
                'model' => $model,
                'attribute' => 'cityID',
                'data' => $model->fetchCityName(),
                'multiple' =开发者_JAVA技巧> false,
                'htmlOptions' => array('size' => 25),
            ));
        ?>


If you have 216,912 option elements, it should ring an alarm bell that there is a better way :)

May I suggest

  • Autocomplete that queries your server with AJAX.
  • Pick postcode first, then show matching suburbs.


I don't do Yii, but there should be some kind of relationships between countries, states, cities right? No one would select city of Taipei then choose CA, U.S.A. as the country and state.

For the States and Cities, I would suggest fetch the acceptable choices via Javascript/AJAX only after the user have selected the Country/State.


See this wiki on creating dependent dropdowns in Yii:

http://www.yiiframework.com/wiki/24/creating-a-dependent-dropdown/

I think you'd be better going with an autocomplete though - the docs are here:

http://www.yiiframework.com/doc/api/1.1/CJuiAutoComplete

It is the jQuery UI Autocomplete which is widely used.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜