New to CI (be kind) |
[eluser]k2zs[/eluser]
I have a few questions... I see reference in the forum where you can use Code: <?php echo base_url();?> Fatal error: Call to undefined function base_url() in ..... I see it defined in my config file, what am I doing wrong? Also I am used to developing dynamic sites where all pages are drawn from a database. I have searched the forum and found a few posts regarding this but it still eludes me. How would I create a common navigational object and deliver pages based in links to specific entries in the database with one record being shown as the default page?
[eluser]ShoKatoo[/eluser]
Simple... Open ./system/application/config/autoload.php and scroll down to Code: $autoload['helper'] = array(); Code: $autoload['helper'] = array('url'); As for the following question... I don't quite get what are you trying to say... please give some more info... Have phun!
[eluser]k2zs[/eluser]
Perfect! Problem one solved I have only heen at this CI stuff since yesterday morning (and I had to attend my first sons wedding yesterday :grrr: ) but I have been able to build quite a bit so far. I've already re-arranged the site structure to get all of the CI stuff out of my web root, and built static header and footer files. I connected to an exiating database and am drawing all of my pages from the "pages" table, but unfortunately they are all being displayed at once. I've been trying to understand models so that I can write my own sql statements but am lost. I am new to MVC and have always used flat file structure... Now onto my other issue... How would I make a common navigational item that draws its items from a database?
[eluser]boldyellow[/eluser]
[quote author="k2zs" date="1287963491"] Now onto my other issue... How would I make a common navigational item that draws its items from a database?[/quote] On a school site I did, the nav model goes to the table of the courses offered and grabs the title of each active course to display in the local navigation. Code: // Controller
[eluser]k2zs[/eluser]
I'm just not getting it. Can you explain the whole thing with actual file names? I have yet to be able to use a model. Where is the controller code calling the model? what is the actual model name? Here is what I did: I have one controller called "main.php" and in it I have: Code: <?php Then I have the model called "subNav_model.php" and in it I have: Code: <?php I created the view to load the subNav and called it "subNav_view.php" and in it I have: Code: <div> When I try running it I get Code: A PHP Error was encountered
[eluser]boldyellow[/eluser]
Hmmm, yeah, alot going on there. I just started with CI a few months ago. I'm not an expert and I'm not a programmer, just a designer. So knowing that, I will proceed to dispense free advice: The MVC concept is all about making your code modular. And it is literally at the core of CI. MVC means you'll likely want to avoid db queries in your Controller. Likewise, not sure you'd want an echo statement in your Model, that's more of a View thing. The CI documentation is great, but can lack specific examples for a raw beginner (like me). But it's a good jumping off point... from there, Google is my best friend. Start with simple code. Just get the basic concepts using a Controller, a Model and a single View. No nav or such, just simple dumb stuff. I started just using a database about alien sightings (inspired by a PHP book I read). Then build on that and add more functionality in your Controller and Views. 'bout the best I can do at this hour... hope this helps you keep going with CI.
[eluser]Bart Mebane[/eluser]
@k2zs: You need to load your model before calling it. Code: $this->load->model('subNav_model');
[eluser]k2zs[/eluser]
Wow!!! I think I'm getting it... My new controller: Code: <?php My new model: Code: <?php The if in the "getPage" method seems a bit messy, I'm sure there are probably better ways of doing it but it works for now. Now I just need to figure out how to pass the pages parentID from "getPage" to "getSubNav" in the model... This stuff is GREAT!! |
Welcome Guest, Not a member yet? Register Sign In |