Yii Framework Forum: کار با آرایه - Yii Framework Forum

Jump to content

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

کار با آرایه آرایه

#1 User is offline   razzaghi.b 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 12-August 13

Posted 22 October 2013 - 03:56 AM

سلام
من ای آرایه رو دارم
می خاوم اون اسم شهر هم بره آخر آرایه اولی

Array
(
    [0] => Doctor Object
        (
            [_new:CActiveRecord:private] => 
            [_attributes:CActiveRecord:private] => Array
                (
                    [id] => 484
                    [id_nezam_pezeshki] => 37587
                    [fname] => حميد 
                    [lname] => قدوسي
                    [city_id] => 1
                    [field_id] => 77
                    [address] => چهارراه سعدي – روبروي بانک مسکن – بن بست دارايي
                    [work_address] => -------
                    [gender] => مرد
                    [id_markaz] => 1
                    [tell] => 4252084
                    [category_id] => 27
                )

            [_related:CActiveRecord:private] => Array
                (
                    [city] => City Object
                        (
                            [_new:CActiveRecord:private] => 
                            [_attributes:CActiveRecord:private] => Array
                                (
                                    [id_city] => 1
                                    [city_name] => زنجان
                                )

                            [_related:CActiveRecord:private] => Array
                                (
                                )

                            [_c:CActiveRecord:private] => 
                            [_pk:CActiveRecord:private] => 1
                            [_alias:CActiveRecord:private] => t
                            [_errors:CModel:private] => Array
                                (
                                )

                            [_validators:CModel:private] => 
                            [_scenario:CModel:private] => update
                            [_e:CComponent:private] => 
                            [_m:CComponent:private] => 
                        )

                )

            [_c:CActiveRecord:private] => 
            [_pk:CActiveRecord:private] => 484
            [_alias:CActiveRecord:private] => t
            [_errors:CModel:private] => Array
                (
                )

            [_validators:CModel:private] => 
            [_scenario:CModel:private] => update
            [_e:CComponent:private] => 
            [_m:CComponent:private] => 
        )


ینی بشه اینطوری
Array
(
    [0] => Doctor Object
        (
            [_new:CActiveRecord:private] => 
            [_attributes:CActiveRecord:private] => Array
                (
                    [id] => 484
                    [id_nezam_pezeshki] => 37587
                    [fname] => حميد 
                    [lname] => قدوسي
                    [city_id] => 1
                    [field_id] => 77
                    [address] => چهارراه سعدي – روبروي بانک مسکن – بن بست دارايي
                    [work_address] => -------
                    [gender] => مرد
                    [id_markaz] => 1
                    [tell] => 4252084
                    [category_id] => 27
                    [city_name] => زنجان
                )

            [_related:CActiveRecord:private] => Array
                (
                    [city] => City Object
                        (
                            [_new:CActiveRecord:private] => 
                            [_attributes:CActiveRecord:private] => Array
                                (
                                    [id_city] => 1
                                    [city_name] => زنجان
                                )

                            [_related:CActiveRecord:private] => Array
                                (
                                )

                            [_c:CActiveRecord:private] => 
                            [_pk:CActiveRecord:private] => 1
                            [_alias:CActiveRecord:private] => t
                            [_errors:CModel:private] => Array
                                (
                                )

                            [_validators:CModel:private] => 
                            [_scenario:CModel:private] => update
                            [_e:CComponent:private] => 
                            [_m:CComponent:private] => 
                        )

                )

            [_c:CActiveRecord:private] => 
            [_pk:CActiveRecord:private] => 484
            [_alias:CActiveRecord:private] => t
            [_errors:CModel:private] => Array
                (
                )

            [_validators:CModel:private] => 
            [_scenario:CModel:private] => update
            [_e:CComponent:private] => 
            [_m:CComponent:private] => 
        )


تو گوگل خیلی گشتم
اینا رو هم پیدا کردم


<?php
$stack = array("orange", "banana");
array_push($stack, "apple", "raspberry");
print_r($stack);
?>
function array_insert (&$array, $position, $insert_array) {
  $first_array = array_splice ($array, 0, $position);
  $array = array_merge ($first_array, $insert_array, $array);
} 
array_insert ($test_array, 2, array ('rowX' => array ('colX' => 'foobar2')));
echo '<pre>'; print_r ($test_array); echo '</pre>'; 

ممنون میشم اگه کمکم کنید
0

#2 User is offline   ahb360 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 32
  • Joined: 15-February 10

Posted 22 October 2013 - 04:00 AM

سلاماین چیزی که شما اینجا دارید یک آبجکتهکه کلاسش هم Doctor هستشما اگه به مدل Doctor یک متغییر اضافه کنید اینجا هم اضافه میشهاگه مشکل داشتی مدل دکتر رو اینجا بفرستید
0

#3 User is offline   chalist 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 46
  • Joined: 16-December 12

Posted 22 October 2013 - 04:02 AM

خب اون رو که با ریلیشن ها دسترسی داری بهتش
ینی :
$model->fname; // حمید
$model->city->name; // زنجان. همشهری هم که هستی :دی

حالا اگه میخای اینطوری که میخای باشه خودت باید یه آرایه ی خالی بسازی و اینا رو توش پر کنی
<?php 
	$array = array();
	foreach ($model as $key => $value) {
		$array[$key] = $value;
	}
	$array['city'] = $model->city->name;
?>

<?php 
/*
 * codeless documentation
 */
?>

@chalist
0

#4 User is offline   razzaghi.b 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 12-August 13

Posted 22 October 2013 - 04:06 AM

بچه های خیلی دمتون گرمه راه حل آرایه خالی رو میرم به نظر بهتره
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