Move code from controller to helpers/models |
Hi, I am building on My_Controller.php a object based on some config variables:
PHP Code: protected $config_columns = array('product_name', array('category' => 'category_name', 'relation' => 'belongs_to'), 'slug_produs', 'price', 'old_price', 'short_description', 'recomandat'); So the foreach build this array: PHP Code: Array I really don't like my practice, how can I split my code into helpers or models? Based on the final object array I build the view. I wanna organize the code in classes. Like PHP Code: class Person {
i don't fully understand what you are trying to do - but the first thing you probably want to do is "separate the concerns".
in other words if you are showing products, then you have the concern of getting the products from a db table or some other data source. which products, what products, what fields to return, etc etc So - Get the Products - that is one concern, and its very appropriate for that to happen in a Model. Very Important - if no products come back - then that is dealt with in the Controller. In other words you are not checking if there are products in your View files. The second concern - which should be completely separate - is how the Products will be displayed in the View or Show the Products. the key there is to create a data structure where its then very easy to show the products in the View with the minimum amount of logic in the View file. Where that stage is done is a personal choice but my suggestion is to use a Model because its the easiest. |
Welcome Guest, Not a member yet? Register Sign In |