Welcome Guest, Not a member yet? Register   Sign In
of controllers, views and templates
#1

I find it hard to explain my problem so i will write in a schematic way.
Rule is : One route -> one Controller::method -> one child template which is part of a parent template called by {% extends "default.twig" %}, when you use twig.
Ok, let's have a blog app, with a page binding :
- the list of posts or one post by his ID - route is 'blog' Controller is 'blog', method is 'index', data will be displayed in the child template
- list of categories - no route, data is displayed in the parent template
- list of last ten posts - no route, data is displayed in the parent template

in controller 'blog', method 'index', code will retrieve list of post, send it to template, but also retrieve list of categories, and list of ten last posts
Same in controller 'blog' method 'show', retrieve one post by his ID, list of categories, and list of ten last posts.
This is ugly and violate DRY rule.
What is the better way to do this ?

Thanks for help
Eric
Reply
#2

It is ok. If this is not the case, make the list of categories in the ViewCell. There will be a separate action, you can insert it into different templates: list, show, admin-list, admin-show...
Simple CI 4 project for beginners codeigniter-expenses ( topic )
Reply
#3

(This post was last modified: 07-21-2024, 05:52 AM by foxbille.)

Woooh, shame on me, did'nt read documentation. Thanks a lot for guiding me.
Will try it immediatly
Tick, tick, tick ...
Works fine!
Thanks!!!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB