• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Linking to a Page

#1
[eluser]bjuneau[/eluser]
Me again... Still trying to wrap my designer brain around how to link to pages... Thank you again for all the help. I'm slowly "getting it" as I work with it... However, I've seemed to have run into a simple but possibly complex problem.

What I am trying to do is simply link to another page from a page.

Note: I am using AG Auth with my process...


Code:
// My "routes.php":
$route['default_controller'] = "admin/admin";
$route['scaffolding_trigger'] = "";


// BEGIN AUTHENTICATION LIBRARY ROUTES
$route['login'] = "admin/admin/login";
$route['logout'] = "admin/admin/logout";
$route['register'] = "admin/admin/register";
$route['admin/dashboard'] = "admin/admin/index";
// END AUTHENTICATION LIBRARY ROUTES

Code:
// My controller "admin.php":

<?php

class Admin extends Application
{
public function __construct()
{
  parent::__construct();
}

public function index()
{
  if(logged_in())
  {
   $this->ag_auth->view('dashboard');
  }
  else
  {
   $this->login();
  }
}

}

// Location: application/controllers/admin/dashboard.php


Code:
// My index.php:

<?php

$this->load->view($this->config->item('auth_views_root') . 'header');

if(isset($data))
{
$this->load->view($this->config->item('auth_views_root') . 'pages/'.$page, $data);
}
else
{
$this->load->view($this->config->item('auth_views_root') . 'pages/'.$page);
}

$this->load->view($this->config->item('auth_views_root') . 'footer');

?>


Code:
// My directory structure for Views is:

- (dir) views
-- (dir) auth
-- (file) header.php
-- (file) footer.php
--- (dir) pages
--- (file) dashboard.php (I want to link to about.php via <a href="about.php">About</a>)
--- (file) about.php

What I've tried:
Code:
<a href="&lt;?php echo site_url('about') ?&gt;">About</a>

When using the above I get "Page Not Found" but when I switch out "about" with an existing page (e.g. register) it works...

#2
[eluser]pickupman[/eluser]
Use site_url when you are wanting to create a link to a page controlled by CI. You seem to be trying to link an actual file. The parameter you pass to it would be 'controller/method'.

#3
[eluser]bjuneau[/eluser]
[quote author="pickupman" date="1355092219"]Use site_url when you are wanting to create a link to a page controlled by CI. You seem to be trying to link an actual file. The parameter you pass to it would be 'controller/method'.[/quote]

I'm thinking I didn't add my page correctly...

#4
[eluser]bjuneau[/eluser]
Is there any documentation on adding new pages? All I'm trying to do is link to a new page that I created.


So if I have:
views/header.php
views/footer.php
views/pages/page1.php (includes header.php & footer.php)
views/pages/page2.php (includes header.php & footer.php)

and I create,

views/pages/page3.php (includes header.php & footer.php)

how do I properly add a page to CI and add a link to it on page1.php? So far I've added a new PHP file to my "views/pages" directory. I've tried linking to it but I get "Page Not Found"...

#5
[eluser]pickupman[/eluser]
Read the [url="http://ellislab.com/codeigniter/user-guide/general/routing.html"]URI routing[/url] from the user guide. CI doesn't work necessary by static php/html files that it seems what you are trying to do.

You will need to stop thinking of pages in that way. You don't "add" pages. Controllers are what handles the logic for displaying pages. The Controller as described in the link above, is the first part of your url. You can have a Pages controller. So a url would look like example.com/index.php/pages. This link will load the Pages controller and execute the index() method when found. Taking this thinking. if you have a Pages controller with an about() method would like example.com/index.php/pages/about.

#6
[eluser]bjuneau[/eluser]
[quote author="pickupman" date="1355099088"]Read the [url="http://ellislab.com/codeigniter/user-guide/general/routing.html"]URI routing[/url] from the user guide. CI doesn't work necessary by static php/html files that it seems what you are trying to do.

You will need to stop thinking of pages in that way. You don't "add" pages. Controllers are what handles the logic for displaying pages. The Controller as described in the link above, is the first part of your url. You can have a Pages controller. So a url would look like example.com/index.php/pages. This link will load the Pages controller and execute the index() method when found. Taking this thinking. if you have a Pages controller with an about() method would like example.com/index.php/pages/about.[/quote]

Right, I think the AG Auth config was throwing me off. I wasn't trying to hit a static page but rather load a view into my template. I basically just created another controller to handle the other views.

Code:
&lt;?php

class Pages extends Application
{
public function __construct()
{
  parent::__construct();
}

public function about()
{
  if(logged_in())
  {
   $this->ag_auth->view('about');
  }
  else
  {
   $this->login();
  }
}
}

Now since everything in this controller will require login and I already have AG Auth working... Is there a prettier way to verify "if(logged_in()) for all functions for a particular controller?

#7
[eluser]pickupman[/eluser]
You would want to create base controllers. Check out Phil Sturgeon's post about [url="http://philsturgeon.co.uk/blog/2010/02/CodeIgniter-Base-Classes-Keeping-it-DRY"]base controllers[/url]. The post shows you have to create Frontend and Backend controllers. Whatever code you place in the __construct() will be executed for any method.

So any controller you need to have admin access will extend the Backend. Any controller that needs login access, you extend the Frontend Controller.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.