Want show home page content only on home page |
[eluser]the_unforgiven[/eluser]
HI All, I'm new to the forums and codeigniter so please be gentle. I have started a project (for testing/learning purposes) and I have an admin system in which i can add all the info and all is working fine but i have a small issue. The home page content shows on every page and i wish to know what would be the correct code to only show this on the home page or index page. I have tried these: But no joy: Code: if (isset($this->request->get['route']) && $this->request->get['path'] == 'welcome'){ Or yes I am using the shopping cart class and backend pro by Kaimonokago If anyone can point me in the right direction it would be very much appreciated, if you need to see any more code let me know what you want to see.
[eluser]TWP Marketing[/eluser]
Use multiple view files and only send the data necessary for each view. If I had to guess, you may only have a single view file and are trying to use it for everything? If you are not already doing so, design your pages using header,content and footer sections (views). Header and footer views tend to be static while the content view(s) change as dictated by site design and flow. This leads to a template style of design, which you may find useful. I know this is very general, but your question is very broad. Please look through the list of tutorials on the wiki: http://codeigniter.com/wiki/Category:Help::Tutorials Do a search on this forum for tutorials, there are several, some more complex than others, but they offer other ways of using CI. Ask questions on the forum, please, we don't bite (much <g>).
[eluser]the_unforgiven[/eluser]
Hi thanks for your reply, I will check that out and I've been referring to the user guide too. I have a welcome controller that sees to control everything I have set up header, content, footer and container views but i need to put some code in like Code: if ($_POST['page']=='welcome' {
[eluser]the_unforgiven[/eluser]
Maybe this will help Pasted all the container page on pastebin here -> http://pastebin.com/A5pxsSSk to save on space.
[eluser]TWP Marketing[/eluser]
[quote author="the_unforgiven" date="1307664543"] But cant seem to get the actuall route as it where right.[/quote] I think I understand that. Follow the data flow; model->controller->view Set up your data first, in the controller, via your model(s). Your data (an array) will be passed to the view from the controller. Controller: Code: $view_data = array(); In the view file, you will be able to echo any element of the three arrays: $header, $footer, $body View: Code: ... This is a simplified structure and the view you pastebin'd is much more complex. I see that you are calling the CI loader from within the view file. I have never done that myself and I see potential problems with that approach. I would create any needed data structures (menus, images, text, forms, etc.) in the controller/model and simply pass that data to the view, using the CI loader. Technically, you don't need a model, but it could greatly simplify the controller code. If this doesn't make enough sense, please feel free to ask.
[eluser]the_unforgiven[/eluser]
Hi thanks for that, I think I understand it, so i don't really need a model then, would the above controller be a new page then same with the view file. Because the pastebin code was the container.php page which is the index.php page if you like that show everything, so would I just do a new controller page then put all the views stuff on that container.php page then?
[eluser]the_unforgiven[/eluser]
I also have this piece of code in welcome.php which is the main controller for everything Code: function customeraccount() {
[eluser]TWP Marketing[/eluser]
[quote author="the_unforgiven" date="1307710359"]Hi thanks for that, I think I understand it, so i don't really need a model then, would the above controller be a new page then same with the view file. Because the pastebin code was the container.php page which is the index.php page if you like that show everything, so would I just do a new controller page then put all the views stuff on that container.php page then?[/quote] Ok, this may get complicated, so bear with me. Re using models; no you don't need to use them, YES, they make your code easier to understand. I use them, extensively. If you find your controller is getting too large, move data access and manipulation code into models. I come from a procedural coding background (yeah, I'm that old), and huge files were normal, but a nightmare to debug and document. Please DO consider using models per the MCV architecture. Next, I see that your code uses the GET variables, because your links are not built around the defacto CI segmented uri's. You CAN do this, BUT, you will spend large amounts of time fighting the CI system (opinion). Please read this thread for some background on the argument around CI's segmented uri vs GET: http://ellislab.com/forums/viewthread/56389/ Next, check the User Guide http://ellislab.com/codeigniter/user-guide/ and decide whether you want to design your project using CI's URI Segment approach: /controller/function/var1... or the $_GET array format. The thread above discusses many of the pro's and con's for these approaches. To be honest, when I start a new project (as you are here?) I really prefer the segmented uri's. They make sense in the [edit] MCV design model (personal opinion, your mileage may vary and other opinions are valid. So please, no flames from the rest of the community). Looking at your Pastbin'd code, I see that you have some experience in PHP. That code is built using the GET array to pass variables. Yes it can be made to work, but you'll miss a lot of CI's ease-of-use and spend more time doing work-arounds. (Again, personal opinion...). And yes this is verbose and I apologise but I hope it helps.
[eluser]the_unforgiven[/eluser]
Thanks mate Thats makes a lot more sens so I would be better off doing the following: Write my own, Controller, Model, View Write new views files to include header, content and footer etc If i understand what you have said in both posts you made that is.... I will have a go and see what happens and let you know, much appreciate the help you given and I hope to get this working. Thanks again |
Welcome Guest, Not a member yet? Register Sign In |