model calling model | or controller calling : correct way?
Posted: Wed Dec 23, 2015 9:04 am
Hi There,
I'm fairly new to PHP and web development. And I'm facing a situation to which there may be multiple ways to do, but which one is correct, I'm unsure of.
Laravel 4.2, PHP 5.5.24 (cli) MySQL 5.6.23 - home brew
I've model for each table.
I've 3 steps in one feature:
My current feature has flow as:
- provides name of pipeline and save
- Create link of tools for the pipeline above created
- get id and update pipeline
In order to create pipeline, I do an insert:
Controller:-
Database:
I return the id after creating new pipeline
Controller:-
I use this id :
pipeline id is foreign key to the analysis_link table.
In short, pipeline 12 will go to 35, 35 uses tool_app -1, then next analysis is 36
36 uses tool_app -2, then next analysis is 37
and so on.
Next, I return the id from analysis_link back to the controller, and update the pipeline:
updated:
Is this correct way?
Or, should I call analysis_link model after inserting pipeline.
And again then and there itself I should update?
I'm now facing similar situation in my code ahead.
Please shed some light.
Thank you
I'm fairly new to PHP and web development. And I'm facing a situation to which there may be multiple ways to do, but which one is correct, I'm unsure of.
Laravel 4.2, PHP 5.5.24 (cli) MySQL 5.6.23 - home brew
I've model for each table.
I've 3 steps in one feature:
My current feature has flow as:
- provides name of pipeline and save
- Create link of tools for the pipeline above created
- get id and update pipeline
In order to create pipeline, I do an insert:
Controller:-
Code: Select all
$pipeline_model_object=new Pipeline_model();
$pipeline_id=$pipeline_model_object->create_new_pipline();
//get pipeline id
Code: Select all
+----+---------------+------------------+
| id | pipeline_name | id_analysis_link |
+----+---------------+------------------+
| 12 | final_test | NULL |
Controller:-
I use this id :
Code: Select all
$pipeline_model_object=new Pipeline_model();
$pipeline_id=$pipeline_model_object->create_new_pipline();
/*
* create new pipeline have its id_analysis_link as NULL
*/
$analysis_id=(new Analysis_link())->create_new_analysis_flow($pipeline_id,$tool_array);
Code: Select all
+----+-------------+-------------+------------------+
| id | id_pipeline | id_tool_app | next_analysis_id |
+----+-------------+-------------+------------------+
| 35 | 12 | 1 | 36 |
| 36 | 12 | 2 | 37 |
| 37 | 12 | 3 | 38 |
| 38 | 12 | 4 | NULL |
+----+-------------+-------------+------------------+
36 uses tool_app -2, then next analysis is 37
and so on.
Next, I return the id from analysis_link back to the controller, and update the pipeline:
Code: Select all
$pipeline_model_object=new Pipeline_model();
$pipeline_id=$pipeline_model_object->create_new_pipline();
/*
* create new pipeline have its id_analysis_link as NULL
*/
$analysis_id=(new Analysis_link())->create_new_analysis_flow($pipeline_id,$tool_array);
/*
* create analysis chain.. and update them there and then
*/
$pipeline_model_object->update_pipeline($pipeline_id,$analysis_id);
Code: Select all
+----+---------------+------------------+
| id | pipeline_name | id_analysis_link |
+----+---------------+------------------+
| 12 | final_test | 35 |
Or, should I call analysis_link model after inserting pipeline.
And again then and there itself I should update?
I'm now facing similar situation in my code ahead.
Please shed some light.
Thank you