Multiple Pages (404 errors) |
[eluser]benaroia[/eluser]
Arg. The problems that arise when you're new at something. I've got a controller called gms, the index() function loads the proper page. So something is working. Now I want to give it a getpage() method that takes a ?page=somepage argument, similar to standard PHP $_GET['page']; Is this possible with CI? Is there a better way of handling multiple database backed pages? Let me extrapolate. I have a view called navbar, that pulls a list of the pages out of a database, then lists them. Code: <div id="navbar"> Now this gives me a 404 error. Even though I think it's right? I'm probably doing something wrong. :down:
[eluser]Fenix[/eluser]
This is how CI uses clean URLs instead of ?page= junk: www.yourpage.com/page/23 Code: function page($page = "default") would output: Code: This is page: 23 I don't know if this helps... you're question is kind of vague to me
[eluser]missionsix[/eluser]
[quote author="Fenix" date="1219454895"]This is how CI uses clean URLs instead of ?page= junk: www.yourpage.com/page/23 Code: function page($page = "default") would output: Code: This is page: 23 I don't know if this helps... you're question is kind of vague to me[/quote] this would be correct if you routed /page/:num to "gms/page" you would do this: Code: class gms { then go to : index.php/gms/page/1/ would output Code: viewing page 1 oh and: Quote: echo '<li><a >page.'">'.$row->page.'</a></li>';wtF?!
[eluser]ehicks727[/eluser]
[quote author="benaroia" date="1219436199"]Is there a better way of handling multiple database backed pages? [/quote] You should create a model that gets your menu items from the database. Call the model from your controller into a data var. Then pass the data to your view. It's not wrong, necessarily, that you're calling your database from your view.. it's just not the most proficient way of doing it.
[eluser]Colin Williams[/eluser]
Quote:It’s not wrong, necessarily, that you’re calling your database from your view.. it’s just not the most proficient way of doing it. Sure, it's not wrong if you're tossing the whole point of MVC separation out the window.
[eluser]benaroia[/eluser]
[quote author="Colin Williams" date="1219551167"] Quote:It’s not wrong, necessarily, that you’re calling your database from your view.. it’s just not the most proficient way of doing it. Sure, it's not wrong if you're tossing the whole point of MVC separation out the window.[/quote] hahaha. I get it. The MVC bit is kinda throwing me for a loop. I want to be able to call a domain name and get it routed to a default view. Then be able to change that view, without changing the domain. From product.com to product.com/buysomething to product.com/buysomething/[product-id] My problem is that I'm not sure where to place the required files (images, css, etc) relative to the domain (default view that is). I'm also not sure how to move the controller from the default for product.com to product.com/buysomething...
[eluser]ehicks727[/eluser]
[quote author="Colin Williams" date="1219551167"]Sure, it's not wrong if you're tossing the whole point of MVC separation out the window.[/quote] Ahh, grasshopper... in coding, there is no right and wrong. There is only more or less efficient. Seriously though, if it WORKS, then it is not WRONG. It's only WRONG if it doesn't work.
[eluser]ehicks727[/eluser]
[quote author="benaroia" date="1219551576"]hahaha. I get it. The MVC bit is kinda throwing me for a loop. I want to be able to call a domain name and get it routed to a default view. Then be able to change that view, without changing the domain. From product.com to product.com/buysomething to product.com/buysomething/[product-id] My problem is that I'm not sure where to place the required files (images, css, etc) relative to the domain (default view that is). I'm also not sure how to move the controller from the default for product.com to product.com/buysomething...[/quote] You really need to read through the user guide http://ellislab.com/codeigniter/user-guide/toc.html Try all the examples, then I found it helpful when I was learning all this to follow through and do the video tutorials. In particular, you need to read up on views. Do the examples and it should start making sense. http://ellislab.com/codeigniter/user-gui...views.html As far as where to keep your assets (css, images, etc.. ) keep them in your root. /css /img /video etc.. The way I use views is that I have one file that is my template. The template references all my css, images, etc. I have a designated area for content that changes from page to page. Create another view, specific to your page (i.e. about.php, contactus.php) and pass that view designation from your controller to your template view. I hope that makes sense. I should probably throw up some code, but it's better if you try to figure it out first... you learn better that way. If you're still struggling after you done some reading and tried the tutorials, let me know, I can give you some pointers.
[eluser]benaroia[/eluser]
How do I get the index.php to show up but only when it's connecting to the "default" controller? I want something like product.com/index.php and then lead to something else like product.com/buy for example. I'll defiantly revisit that user guide, I went through it once, let's try it again.
[eluser]Colin Williams[/eluser]
Quote:Ahh, grasshopper… in coding, there is no right and wrong. There is only more or less efficient. True, but it's not responsible to suggest inefficient practices just for the sake of argument. benaroia, ehicks727 laid out a pretty good example on how to use views in an efficient, logical way. Not sure what you're bringing up now with the index.php thing. Sounds to me like your introducing pointless conditions that go against CI's conventions. But, when you want to effect how the server responds to URI's, you'll want to use mod_rewrite rules. |
Welcome Guest, Not a member yet? Register Sign In |