Answer the question
In order to leave comments, you need to log in
Why is this done, what can be done with the code next?
Good afternoon.
They contacted me with a proposal to make some changes on the site, which is developed on yii2.
While it was required to configure urlManager(), but there will be a bunch of other edits.
Website for the sale / hire of cars.
Looking into one of the controllers, I'm a little "hung". A controller of 1,500 lines, most of the actions in it receive information from the database about cars, but with different parameters.
Here is an example of such an action, choosing from a database of cars in a given region.
public function actionSearchByRegion($region = null)
{
if (\Yii::$app->request->isGet) {
$region = \Yii::$app->request->get('region-name');
$region = str_replace('-', ' ', $region);
// $region = substr($region, 0, 5);
$region = Regions::find()
->select('region_id')
->where(['like', 'region_name', $region])
->asArray()
->one();
if (!empty($region)) {
$cars = Cars::find()
->where(['=', 'car_region', $region['region_id']])
->andWhere(['=', 'car_sold', 0])
->orderBy(['id' => SORT_DESC])
->asArray();
$query = $cars;
$countQuery = clone $query;
$pages = new Pagination([
'totalCount' => $countQuery->count(),
'defaultPageSize' => 12,
]);
$models = $query->offset($pages->offset)->limit($pages->limit)->all();
return $this->render('search', [
'cars_res' => $models,
'pages' => $pages,
]);
}
}
}
<?= $form->field($searchcar, 'city')->label('Okres')->dropDownList(
// ArrayHelper::map(\backend\models\City::find()->where(['region_id' => $searchcar->state])->asArray()->all(), 'city_id', 'city_name'),
ArrayHelper::map(\backend\models\City::find()->where(['region_id' => $_GET['SearchCar']['state'] ? $_GET['SearchCar']['state'] : $_GET['region']])->asArray()->all(), 'city_id', 'city_name'),
[
'prompt' => 'Vyberte okres',
///'value' => $_GET['SearchCar']['city'] ? $_GET['SearchCar']['city'] : $_GET['city']
]
) ?>
Answer the question
In order to leave comments, you need to log in
I do not defend this code and I do not like it at all, but there is a fictional ideal world and there is a real one. In the real world, this happens very often.
To do nothing. You can try to explain the problem to the client, but most likely he will refuse to redo the project. Are you sure that with your "not very much experience" you can quickly and efficiently rewrite? Why does the client need to pay a second time if he does not see any changes from the UI side?
Do your job and inform the client about problems that will become even bigger in the future.
He implemented the task using his experience and capabilities, and received money for it. He didn't try to make the world a better place.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question