Welcome Guest, Not a member yet? Register   Sign In
Dynamic page
#1

[eluser]Helmasaur[/eluser]
Hi !

I'm a just began to use Code-Igniter. I'm very happy of my choice. It's a very good framework. But I have a problem.

I would like to avoid to change the menu in each pages. That's why I've included the views : html head, header, menu and footer (also the content but it's evident).

My habit is to include the page in a PHP file where there's already the html head, heade, menu and footer.
For example, before, it could be like this :
Code:
?page=country&country=france

I would like to know if it's possible to use a similar system and if yes, how.


PS : I profit to ask why it's better to use the image function from CI than HTML
#2

[eluser]Phil Sturgeon[/eluser]
Take a look in the guide to see how CI URL's work and take a look at the URI library.

The reasons for using CI helper functions like image() and form_open() are small and unimportant. I use some as it cleans up my code, some to provide shared logic and some as CI's features are nicely integrated.

If you use the form_open and close functions, it will eventually (or perhaps already does) help with XSS attacks, etc. Helper functions are just there to help, not really that important.
#3

[eluser]Helmasaur[/eluser]
Thank you for the links. I read already the first one but not the second. And it's in this one I have the answer.
I'll read this article and ask questions if I don't understand.

It's really easier to use a framework.
#4

[eluser]Helmasaur[/eluser]
I would like to know if is should use a FrontCotnroler (with conditions) to be aible to include the pages according to the URL.
#5

[eluser]jdfwarrior[/eluser]
Are you asking if you should use a controller? If so, then yes, that is the purpose of using a MVC framework. The controller is an object with a set of inner functions. The functions are called dependent upon what is called from the url.

For instance: http://www.example.com/country/france

Would load the Country controller and execute the France function. It is there that you would need to load the information pertaining to France.
#6

[eluser]Helmasaur[/eluser]
OK, I understand how to do this part. Thank you !

But if I don't wont all the time to copy or modify <head>, the menu, the header and the footer, how do I do ?

Code:
<html>
  <head>
  </head>
  <body>
    <div id="header">
    </div>
    <div id="menu">
    </div>
    <div id="content">
      &lt;?php include('content.php'); ?&gt;
    </div>
    <div id="footer">
    </div>
  &lt;/body&gt;
&lt;/html&gt;

How do I do to do this with CI ?
#7

[eluser]jdfwarrior[/eluser]
Ok didn't you say that you had these items split up into multiple files/views? If you do, just load those views from the controller/function.

Like..
Code:
class Country extends Controller {

   function index() {

     $this->load->view('head');
     $this->load->view('header');
     $this->load->view('menu');
     $this->load->view('index_content');
     $this->load->view('footer');

   }

   function France() {

     $this->load->view('head');
     $this->load->view('header');
     $this->load->view('menu');
     $this->load->view('index_content');
     $this->load->view('footer');

   }

}
#8

[eluser]Helmasaur[/eluser]
I did something like this. What I'm searching to do it's :
— When the page chosen is country, the country view is included in the general view
— If a country is chosen, we take the data from the DB and we use this in the country view
— If there is no country chosen, a menu of all the countries of the DB is included

I don't have an other example but I would like (if it's possible) to not divide into, head, header, menu, footer the principal view but to include in a general view the page request.
#9

[eluser]jdfwarrior[/eluser]
— When the page chosen is country, the country view is included in the general view
For this you would need the Country controller and the default index function. Index function is called by default if no function is specified (example.com/country)

— If a country is chosen, we take the data from the DB and we use this in the country view
For this, if there is a known list of countries the user would chose from, you COULD create a function for each, but it would probably be better to just use the _remap function inside the country controller. Use it, pick the country name from the url (example.com/country/countryname), check the database to make sure there is an entry for it. If there is, display the data, if not, display an error

— If there is no country chosen, a menu of all the countries of the DB is included
This is the same as navigating to the country page. (example.com/country). You would use the index function within the Country controller.

[quote author="Helmasaur" date="1240411901"]
I don't have an other example but I would like (if it's possible) to not divide into, head, header, menu, footer the principal view but to include in a general view the page request.[/quote]

I dont fully understand what your asking for here. Are you saying you would rather not have it split into multiple files? You dont have to. You'll pulling database content, you could generate the code in the controller or a model and pass it to the controller, then the view to be displayed. That way you would have a single view file, with a view variables scattered around that handled anything that was dynamic
#10

[eluser]Helmasaur[/eluser]
Thanks, it helps me alot !
I'll try with _remap. I would like juste to know if it's better to use _remap function or country($country).

Quote:I dont fully understand what your asking for here. Are you saying you would rather not have it split into multiple files? You dont have to. You’ll pulling database content, you could generate the code in the controller or a model and pass it to the controller, then the view to be displayed. That way you would have a single view file, with a view variables scattered around that handled anything that was dynamic
Whar I would like is like the previous example :
[/quote]
Code:
&lt;html&gt;
  &lt;head&gt;
  &lt;/head&gt;
  &lt;body&gt;
    <div id="header">
    </div>
    <div id="menu">
    </div>
    <div id="content">
      &lt;?php include($_GET['page']); ?&gt;
    </div>
    <div id="footer">
    </div>
  &lt;/body&gt;
&lt;/html&gt;
I've change include. I think it's easier to understand.
I would like to have this view and include after the controller wich the user asks.
I hope I have explain bettter.




Theme © iAndrew 2016 - Forum software by © MyBB