コントローラー public function action_property() { $lang = Config::get("language"); $houses = \Model_House::query()->where("mark","NOT LIKE","%consigned_management%")->order_by(array("city_id","name"))->get(); $state = array(); $city =array(); foreach ($houses as $key => $value){ $state[$key] = $value->city->state->id; $city[$key]= $value->city->id; } array_multisort($state,$city, SORT_ASC, $houses); usort($houses,function ($left, $right) { // state_idが13かどうか if($left->city->state->id == 13 && $right->city->state->id != 13) { return -1; } if($left->city->state->id != 13 && $right->city->state->id == 13) { return 1; } // state_idの昇順 if($left->city->state->id < $right->city->state->id) { return -1; } else if($left->city->state->id > $right->city->state->id) { return 1; } // city_idの昇順 if($left->city->id > $right->city->id) { return -1; } else if($left->city->id < $right->city->id) { return 1; } // nameの昇順 return strnatcmp($left->name, $right->name); return 0; }); parent::$_view->set('content', ViewModel::forge('member/market/property')->set('houses',$houses)); return parent::$_view; }
View Property.php <?php class View_Member_Market_Property extends ViewModel { public function view() { } }
views Property.php <article> <h3 class="h_pat01"><span>Unusable property</span>都道府県建物</h3> </article> <section> <div class="pointbox"> <table> <tr> <th><?php echo "都道府県"?></th> <th><?php echo "市区町村"?></th> <th><?php echo "建物名"?></th> </tr> <?php foreach ($houses as $house):?> <tr> <?php if ($lang == "jp"): ?> <td><?php echo $house->city->state->name ?></td> <td><?php echo $house->city->name ?></td> <td><a href="/house/<?php echo $house->id ?>" target="_blank"><?php echo $house->house_data->name ?></a></td> <?php $names =\Model_HouseData::query()->select("name")->where("house_id","=","$house->id")->where("lang","=","$lang")->get(); ?> <?php else: ?> <td><?php echo $house->city->state->eng ?></td> <td><?php echo $house->city->eng ?></td> <?php $names =\Model_HouseData::query()->select("name")->where("house_id","=","$house->id")->where("lang","=","$lang")->get(); ?> <?php foreach ($names as $name):?> <td><a href="/eng/house/<?php echo $house->id ?>" target="_blank"><?php echo $name->name ?></a></td> <?php endforeach ?> <?php endif ?> </tr> <?php endforeach ?> </table> </div> </section> </section>
このようなコードを書いたのですが
Trying to get property of non-objectと
コントローラの
$state[$key] = $value->city->state->id;
部分で怒られてしまいます。
ローカル環境で問題なく動いていたのですが
サーバーで実行したら動かなくなってしましました
どこを修正すれば動くようになりますでしょうか?
追記
foreach ($houses as $key => $value){ if(empty($value)) { $state[$key] = $value->city->state->id; $city[$key] = $value->city->id; } else { continue; } } array_multisort($state,$city, SORT_ASC, $houses);
とnull時にスキップ処理を書いたのですが
array_multisort(): Array sizes are inconsistent
とarray_multisort($state,$city, SORT_ASC, $houses);
で配列の問題で怒られてしまいました。。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/04/20 04:25
2017/04/20 05:36