0

I am trying to build an application that can search the database for different City information. (for example: if the user click New York, it will show lots of information about New York.) Do I have to create different controllers for different cities? like New York controller -> New York Model. Seattle controller -> Seattle Model. Chicago controller -> Chicago Model That sounds redundant. What is the best way to approach my problem. Thanks for the helps.

1 Answer 1

1

You could have a City model with a lookup function that accepts a city name as a parameter and returns whatever relevant data. Then, you'll have a controller that accepts a city as a parameter, too. So, for example, http://localhost/index.php/city/lookup/new_york where city is the controller, lookup is the function, and new_york is the parameter to the function.

The lookup function in the controller would pass the parameter it received to the city model lookup function. Whatever the model returns, the controller would pass to the view to be rendered.

You should probably not have a separate controller and model for each city.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I thought about your way before I posted, just wasn't sure if this is the best practice. Now I know i can do it now. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.