Welcome Guest, Not a member yet? Register   Sign In
Display fetch data in the database inside the view
#1

[eluser]Beginers[/eluser]
Hi All,


I read some topic here about displaying data inside the view is a bad practice?

Why do they say its a bad practice? They say it would be better if you display it

inside the controller. Could anyone show me how to display the data in the controller?

Please suggest me some tutorial about good practices?


Best regards,
Beginners
#2

[eluser]Otemu[/eluser]
Hi,

Generally what should go in the view is as follows:

Should mainly contain presentational code, such as HTML, and simple PHP code to traverse, format and render data;

should avoid containing code that performs explicit DB queries. Such code is better placed in models.

should avoid direct access to $_GET, $_POST, or other similar variables that represent the end user request. This is the controller's job. The view should be focused on the display and layout of the data provided to it by the controller and/or model, but not attempting to access request variables or the database directly.

may access properties and methods of controllers and models directly. However, this should be done only for the purpose of presentation.

Source here although the tips apply to the yii framework the concepts are more or less the same for codeigniter

Check out the CodeIgniter From Scratch tutorials found here





Theme © iAndrew 2016 - Forum software by © MyBB