Please Help with routing |
Hello all, I'm starting with CI4 (used CI3 for some projects) but this is my first time using routes and I want to know what do you recommend for this:
In my new project I want to have a website, its almost only static pages with some database calls (cities and product categories) and also will have a user area where they will be able to manage products. According to docs should be like this: /app <-- Everything else in the app /website <-- All related to website /public /system /tests /writable Website part should have only one controller and a view for any page (only 4 pages) and should work in root like this: domain.com (home page) domain.com/services domain.com/products domain.com/contact App part should have everything else and should work with 'app' (or whatever) prefix like: domain.com/app/login domain.com/app/users domain.com/app/products domain.com/app/cities . . Is this ok? Can anyone help me please with a routing example for achieving this? Also should I use .env file for app settings or is it a better practice to create a dedicated config file for my app?
If you look at the Tutorial in the CodeIgniter 4 User Guide it will explain it all to you.
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
reading the docs will explain everything thats true, but a little guidance to get you in the right direction .We all need a little help :^)
At some point there will be updates and probably updates for additional software you don't know of yet and don't think you need when you do its going to be easier with composer. So i would say give https://getcomposer.org/ a good read first. There are options for CI4 , my preference is for appstarter which you can install using composer. I have a core appstarter called basic to play with some concepts i'm learning. When you use a command terminal and cd say to Desktop and use this command: Code: composer create-project codeigniter4/appstarter --no-dev Code: php composer.phar create-project codeigniter4/appstarter --no-dev Code: basic your controllers go in contollers, views go in views and then for css, images such as logo that won't change , go to public and make directories called " images", "css" "js", "sounds", . Then put your assetts such as your css in css directory..sound clips in sounds.. yep you got the idea. I'm using sqlite database and i put those 2 in writable, because yep its writable and a database needs to be written too . Last bit to display appropriate page for domain.com/cities you create a route in Config/Routes.php lets say: $routes->get('/', 'Home::index'); //above is home route it uses Controller Hone and method index $routes->get('cities', 'City::index'); "cities" tells system that when it gets a get request with domain.com/cities it should use a controller called City.php and its method index() { } inside the method index you tell system what to do . read docs on getting started.
Thank you so much for your guide captain-sensible, already had my project installed even with layout but Im going to do everything again to give composer a try
Ok just to update if anyone is interested, i decided I was overcomplicating this with the prefix I wanted to separate app from website now Im going with a structure like this:
/app --/controllers ----/app/ <-- Everything else in the app ----website.php <-- All related to website /public /system /tests /writable |
Welcome Guest, Not a member yet? Register Sign In |