Welcome Guest, Not a member yet? Register   Sign In
Navigation like a site without framework
#1

[eluser]Haskabab[/eluser]
Hello guys!

I'm new to CI but i definitely see it's capabilities and I can't wait to fully master it. I've read the whole user guide and watched some screencasts about how it works and I'm getting the hang of it already.

The only question I have that remains unanswered is how I get a navigation system to work.

Normally when creation a site I would have an index.php and within that the page's layout and a snippet for getting the file to include (what page to show) through the $_GET.

But how do I get the same effect using codeIgniter? Since I need to make a view file to view the site, how do I include a page withing a view file? Or am I getting the wrong idea?

If anybody has anything helpful about how to achieve a navigation system of some sort, please reply!

Thanks in advance,
Nick
#2

[eluser]Michael Wales[/eluser]
A view can itself load a view, so you load a master view which loads your partial view based on the URI passed by your controller.
#3

[eluser]Haskabab[/eluser]
Okay sweet, but how does it interact with different controllers then?

It might be a dumb question but I'm not getting the structure that should be used :S

EDIT: Never mind, I think I understand how and what to do. If you got anything to add though, feel free to reply ^^
#4

[eluser]brianw1975[/eluser]
I think you are getting the wrong idea...

before I go on.... you are saying that your old links used to be index.php?page=this&that=theother

and based on the _GET you would include a file?

if so... did you ever get hacked? I had a friend do that a long time ago and his entire VPS got disconnected because of an XSS assualt.

So moving on... you aren't loading a page per se, you are loading a function, aka a controller.

As you know the controller takes in the data passed to it, sends whatever it needs to to the Model takes that data back, and then loads a view and passes the data to the view....

Now, what you probably didn't realize because it isn't really discussed in the userguide or most screen tuts is that just like most women can have more than one child... a controller can load more than one view.

The first view is called to generate the navigational menu and stored in the data array var that is then passed to the main view file; hence, your logic could go something along the lines of:

Code:
//excuse the code, its probably wrong, and I don't use the views as CI implements them.
$data[header] = $this->load->view("header.html",$someinfo,true);  //this last part is to return the output
$data[footer] = $this->load->view("footer.html",$someOtherinfo,true);
$this->load->view("main-template.html",$data);

Then in your main-template.html file you simply do with 'header' and 'footer' as you wish.
#5

[eluser]Haskabab[/eluser]
Thanks, that was exactly what I needed to know!

And you're correct about how I used the $_GET to include the requested page, but never got hacked though. I always used a switch statement to check if the requested page was supposed to be requested and all variables passed in the $_GET would mostly have been escaped with mysql_real_escape_string() before using it to retrieve data from a database.

Not sure if that was supposed to not get me hacked but I never had any (noticable) problems with it.

And a lot of thanks for that little snippet, I finally understand and you just saved me a lot of researching Big Grin
#6

[eluser]Crimp[/eluser]
Just be aware, also, that URLs like this could be pointed at another file. When the police recently launched their expensive new web page, they offered this handy feature. Soon, of course, you could go to "their" page and see images of the chief of police in new poses...
#7

[eluser]Haskabab[/eluser]
[quote author="Crimp" date="1265467885"]Just be aware, also, that URLs like this could be pointed at another file. When the police recently launched their expensive new web page, they offered this handy feature. Soon, of course, you could go to "their" page and see images of the chief of police in new poses...[/quote]

What exactly do you mean?
#8

[eluser]Crimp[/eluser]
I'm speaking generally. It's just a less (?) sinister variation of XSS. If values are not checked, external content of any kind can be loaded with the URL scheme. People interested in passwords and credit card numbers find this "feature" especially useful. CI, by default, checks if the controller and method exists and leaves it up to you to check and clean any arguments in further segments. FWIW: I do as brianw1975 above - split views into smaller parts for reuse. I stick a folder called /includes (carried over from EE) in the system /views folder and load those when and where needed. Remember that you can also load a view directly in the view - you do not need to pass it as a var from controller to view. Unless there is a really compelling reason to use GET and query strings, I'd go with the CI way of doing things. It's clean and easy.
#9

[eluser]Haskabab[/eluser]
[quote author="Crimp" date="1265482460"]I'm speaking generally. It's just a less (?) sinister variation of XSS. If values are not checked, external content of any kind can be loaded with the URL scheme. People interested in passwords and credit card numbers find this "feature" especially useful. CI, by default, checks if the controller and method exists and leaves it up to you to check and clean any arguments in further segments. FWIW: I do as brianw1975 above - split views into smaller parts for reuse. I stick a folder called /includes (carried over from EE) in the system /views folder and load those when and where needed. Remember that you can also load a view directly in the view - you do not need to pass it as a var from controller to view. Unless there is a really compelling reason to use GET and query strings, I'd go with the CI way of doing things. It's clean and easy.[/quote]

Okay understood, but let's say i want a dynamic user control panel included in my main view file. Which shows a login-form if the user is not logged in and a small control panel if the user IS logged in. Will i need to make 2 separate view files or can i check that in a view file? Because i think it's the job of the controller. Not sure about that, any thoughts?
#10

[eluser]Crimp[/eluser]
You check login in the controller and load two different HTML view files based on the conditional (logged in or not): login form, cpanel. Keep application logic in the controller. Limit logic in the view files to "layout" logic - if so and so, display this HTML, otherwise this HTML.




Theme © iAndrew 2016 - Forum software by © MyBB