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

[eluser]jdfwarrior[/eluser]
Use _remap. Here's something to get you started.

Code:
<?php

if ( ! defined('BASEPATH') )
    exit( 'No direct script access allowed' );

/**
* Country Controller
*
* @uses
* @created    4/22/2009
*
**/

class Country extends Controller
{

    /**
     * Default Function
     * - Executed in the case of no function specified
     *
     * @param None
     * @returns None
     *
     **/

    function index()
    {
        //Load Generic Country View
        //$this->load->view('template');
    }

    /**
     * Remap Function
     * - Routes All Function Calls
     *
     * @param     $func - Function to call
     * @returns None
     *
     **/

    function _remap( $func )
    {

        switch ( $func )
        {
            case "index":
                $this->index();
            default:
                //Connect to the database, look for the page
                //named $func, if it exists, get the data for it.
                //Store the data for that page in a variable
                //Pass that variable to your view.
                //$this->load->view('template', $page_data);
        }

    }

}

You wouldn't have to use the include function. When you load a view and pass the data to it, that data is accessible within the view. Seems like your not really experienced with loading views and such with CI. Go back and check out the user guide articles on Views and Controllers
#12

[eluser]Helmasaur[/eluser]
It's like this I wanted to do like this.
But I would like to know of to do if for examle I want to display for example the texte :
Code:
<p>Population</p>

I should do like this ?
Code:
$data['title1'] = '';
$data['title2'] = '';
$data['text1'] = '';
$data['text2'] = '';
$data['image1'] = '';
$data['image2'] = '';
// and more…

Or I can use the language function ?
#13

[eluser]jdfwarrior[/eluser]
This is an example of loading the data in the controller:

Code:
&lt;?php

if ( ! defined('BASEPATH') )
    exit( 'No direct script access allowed' );

/**
* Country Controller
*
* @uses
* @created    4/22/2009
*
**/

class Country extends Controller
{

    /**
     * Default Function
     * - Executed in the case of no function specified
     *
     * @param None
     * @returns None
     *
     **/

    function index()
    {
        //Load Generic Country View
        $places = array('France', 'Switzerland', 'Germany', 'Austria', 'China');
        
        $page_data = array(
            'page_title'=>'This is the page title',
            'page_author'=>'I am the page author',
            'list_items'=>$places
        );

        $this->load->view('template', $page_data);
        
        
    }

}

This would be an example of the view file named template.php that is loaded from the controller, and displaying the data that was set in the controller.

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html&gt;

&lt;head&gt;
    &lt;meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /&gt;
    &lt;meta name="author" content="&lt;?=$page_author?&gt;" /&gt;

    &lt;title&gt;&lt;?=$page_title?&gt;&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;

<ul>
&lt;? foreach ($list_items as $place): ?&gt;

    <li>&lt;?=$place?&gt;</li>

&lt;? endforeach; ?&gt;
</ul>

&lt;/body&gt;
&lt;/html&gt;

You load data into an array variable in the controller and then pass that variable to the view. Each item is then accessible within the view file.
#14

[eluser]Helmasaur[/eluser]
OK thank you very much.
I can create my site now !

EDIT :
Uh. Yes it works well. But if I want to use the same view with different structure in the body. How do I should do ?
(Escuse-me)
#15

[eluser]jdfwarrior[/eluser]
Do the same thing for different functions. Just change the data that is loaded in the controller and pass that data to the view.
#16

[eluser]jdfwarrior[/eluser]
You really should go back and read through the documentation more though. I can tell you how to do little things all day long, but if you havent read through the documentation and understand what your doing, then you'll never be able to do this stuff alone.

CI has great documentation. It's really easy to learn.
#17

[eluser]Helmasaur[/eluser]
Yes I know it. It's very good but I would like to know if there is a function to have a view with all exept the content.
And include the content wich is riten in the URL : example.com/index.php/page/sub_page

In the global view is loaded the content and the data comes from for example the database with the filter : sub_page.

All is moreless done but I would like to know if with CI, it's possible to do like this or I should use all the time the inclusion of head, header and footer.
#18

[eluser]jdfwarrior[/eluser]
That is where you get into using the _remap function like I showed you earlier.

The way CI is set up, it load/calls things in this manner.
http://www.example.com/controller-name/f.../arg2/etc/

So if you entered example.com/country/France in the url, it would load the Country controller, and call the France function. In your situation, you do not want to have to create a function for all the possibilities. You would use the _remap function, which overrides calling functions by the name specified in the url. You catch the name in the url with the _remap function and from there, determine how to handle the data. So, in the example I gave you earlier.

Code:
function _remap($func) {
    switch ($func) {
        case "index": $this->index();
                default: {

                        //Your code would go here.

                        //Initiate database query to check and see if a page named $func
                        //exists in the database. If it does, retrieve the information for
                        //that page and store it in variables as you did in the index function.
                        //Once you have that information, load the view you want, and pass the
                        //data you got from the database, to the view for display.

                        //If the page is not found to exist in the database, then use show_404()
                        //function to display an error to the user.
                }
    }
}
#19

[eluser]Helmasaur[/eluser]
OK, thank you. I'll do like this. I was not sure I'll be aible to do what I wanted. But if you say it's this. I'll try.
#20

[eluser]jdfwarrior[/eluser]
This will work if I understand what you are wanting to do correctly.

I have used this method before. A project I worked on previously, I wanted the Administrative users of the site to be able to create new pages on the site, similar to a content management system. So I laid down nothing but a frame for the site. All pages were database entries. Urls were in the structure of example.com/pages/pagename. The remap function would check the database for a page that was identified by pagename. If it existed, the data was retrieved, and loaded into a view. Otherwise, it would display a 404 error. You can also take it one step further for scenarios such as mine. I used Routes to remove 'pages' from the url. So a page that was previously access via http://www.example.com/pages/directory, would now be access via http://www.example.com/directory because of the Routes I had created.




Theme © iAndrew 2016 - Forum software by © MyBB