Welcome Guest, Not a member yet? Register   Sign In
How to show same view by diferent parameters
#1

I need an advice.

I have a User model and id Card model (relationship one-to-one). Database tables: User (id, card_id, ...), Cards (id, card_number,...).

I have created a user controller to show details by user_id.

(url)/user/details/{user_id}

I also want to show the same details page when searching by card_number. What's the recommended way to do it?

Should I create a method within Card controller to get user_id by posted card_id and redirect to user/details/{user_id}?
Reply
#2

@itvel,

You could do a couple of things...

1. You could create a model that calls both the user and card models and merges the data into an array.
2. You could create a view on the database that connects the user and card tables and then create a model that uses either the user id or card id to call the view to get the data.
Reply
#3

No need to make 2 functions for this only one thing you have to need 

1) join query for both table (user and user_cards)
2) pass a dynamic parameter for ex if you want to get details from user id 

$this->your-model->commonfunction('users.user_id',$id)
also same thing with use card detail 
$this->your-model->commonfunction('card_details.card_number',$id)


in your model
function commonfunction(where_1 , $value){
// make where paramites dymanic
}
Reply




Theme © iAndrew 2016 - Forum software by © MyBB