Welcome Guest, Not a member yet? Register   Sign In
href to display page
#4

(This post was last modified: 11-18-2019, 12:33 PM by dave friend.)

(11-18-2019, 10:34 AM)dmorgan20 Wrote: I've tried this to no avail.

I've copied the tutorial and it doesn't exactly break it down step by step for someone with no knowledge.

Example, its doesn't say where this needs to be, does it go at the bottom of the pages.php controller?  Is it meant to have a } at the end and one taken away from the class? Because the manual doesn't explain it

    public function view($page = 'home')
    {
            if ( ! file_exists(APPPATH.'views/pages/'.$page.'.php'))
            {
                    // Whoops, we don't have a page for that!
                    show_404();
            }

            $data['title'] = ucfirst($page); // Capitalize the first letter

            $this->load->view('templates/header', $data);
            $this->load->view('pages/'.$page, $data);
            $this->load->view('templates/footer', $data);
    }

This might sound snarky but that's not my intent. Early in the tutorial, you created an empty view function. The above adds code to that function. That seems pretty obvious since the code comes in a section called Adding logic to the controller. (OK, that is snarky. Please forgive me.)

Now, to answer the question in the OP.

If you have worked all the way through the Static Pages tutorial page, then you should have added a couple of $routes. (This is explained at the bottom of the tutorial page.)  If that is done correctly you can browse to http://example.com/index.php and will see the "home" page.

NOTE: I have added "index.php" to the URL examples here because I assume you are not using a .htaccess file that will rewrite URLs so they don't need to include "index.php". If you have set up .htaccess then you don't need to use "index.php" in the URLs as shown here.

If you wanted a link on the "home" page that sends a user to the "bookings" page it would look like this.

Code:
<a href="index.php/bookings"><span class=""></span>BOOK NOW</a>

If you have .htaccess working then the link would be

Code:
<a href="bookings"><span class=""></span>BOOK NOW</a>

There's a bit of magic happening due to the combination of routes and the definition of Pages::view().

"bookings" is the name of the view file that winds up being the argument to view(), i.e. Pages::view('bookings'). The view file is at /application/views/Bookings.php.

Hope that helps.
Reply


Messages In This Thread
href to display page - by dmorgan20 - 11-17-2019, 08:00 AM
RE: href to display page - by dave friend - 11-17-2019, 01:33 PM
RE: href to display page - by dmorgan20 - 11-18-2019, 10:34 AM
RE: href to display page - by dave friend - 11-18-2019, 12:23 PM
RE: href to display page - by dmorgan20 - 11-18-2019, 01:59 PM



Theme © iAndrew 2016 - Forum software by © MyBB