Welcome Guest, Not a member yet? Register   Sign In
Help with planning a CI project
#11

[eluser]theprodigy[/eluser]
you can do that, but you would need to either setup a route for it in your routes config file, or add another function to your page class named about-us, or add a _remap function.

routes example (I believe that should do it, although I may be wrong):
Code:
$route['default_controller'] = "page";
$route['page/:any/:any'] = "page/pages/$2";

about-us example:
Code:
function about-us($page) {
    $this->pages($page); //no need to copy / paste the code, just call the function that has it
}

_remap (I personally don't use this a lot, but you can read about it here)
#12

[eluser]invision[/eluser]
Thanks for the reply.

Aaaah so in my Pages Controller, I should have functions for all my 'directories' like 'about-us','services' etc?

Great, I will test this example out in a second if you're not rushing off Smile


Thanks again
#13

[eluser]theprodigy[/eluser]
If you want something other than "pages" to display in the url (like your about-us), then yes, you would need any one of the options i listed above, since you would be altering the default behavior of CI (domain.tld/controller/method/params).
#14

[eluser]invision[/eluser]
Just a headsup.

I don't think CodeIgniter likes the hyphen in about-us.

Any way to fix this, or should I just go with aboutus instead?
#15

[eluser]theprodigy[/eluser]
you could change the hyphen to an underscore, but I'm not sure why CI would have a problem with the hyphen. What error is it throwing?
#16

[eluser]invision[/eluser]
Brilliant!

Ive temp changed about-us to aboutus in my Page controller.

Think I'm almost there with this.

However, when I visit:
http://www.site.com/index.php/page/aboutus/location

I'm getting these 3 error messages:

Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined index: title

Filename: controllers/page.php

Line Number: 23

Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined index: title

Filename: views/public_page.php

Line Number: 10

Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined index: body

Filename: views/public_page.php

Line Number: 11



Any ideas what may be causing this?
#17

[eluser]theprodigy[/eluser]
those errors are coming from your views. It sounds like you are trying to access indexes in an array that don't exist.
#18

[eluser]invision[/eluser]
Do you want me to post my current Model / Controller / View code for the Pages area of my site?

Really appreciate all your help with this, feel like I'm making a great dent in this so far.
#19

[eluser]theprodigy[/eluser]
yes please. Show me what you got
#20

[eluser]invision[/eluser]
Controller
Code:
<?php
class Page extends Controller {
  function Page(){
    parent::Controller();
    session_start();
  }

  function index(){
    // say 'home' is the value of the slug in my sql table
    $data['page_data'] = $this->MPages->getPageBySlug('home');
    $data['title'] = "Welcome";
    $data['main'] = 'public_home';
    $this->load->vars($data);
    $this->load->view('template');  
  }
  
  function aboutus($page) {
    $this->pages($page); //no need to copy / paste the code, just call the function that has it
  }
  
  function pages($slug){
    $data['page_data'] = $this->MPages->getPageBySlug($slug);
    $data['title'] = $data['page_data']['title'];
    $data['main'] = 'public_page';
    $this->load->vars($data);
    $this->load->view('template');  
  }
  
}

Model:
Code:
<?php
class MPages extends Model{

    function MPages(){
        parent::Model();
    }
    
    function getPageBySlug($slug){
        $data = array();
        $this->db->where('slug',$slug);
        $this->db->limit(1);
        $Q = $this->db->get('pages');
        if ($Q->num_rows() > 0){
          $data = $Q->row_array();
        }
        $Q->free_result();    
        return $data;    
    }

}

Views:
Code:
<?php
// public_page.php
echo auto_typography($post_data['title']);
echo auto_typography($post_data['body']);

Code:
// template.php
<!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=UTF-8" /&gt;
&lt;title&gt;&lt;?php echo $title; ?&gt;&lt;/title&gt;
&lt;link href="/serconia/includes/css/main.css" rel="stylesheet" type="text/css" /&gt;
&lt;/head&gt;

&lt;body class="twoColFixLtHdr"&gt;

<div id="container">

  <div id="header">
    <h1>&lt;?php echo $title;?&gt;</h1>
  </div>
  
  <div id="sidebar1">
    &lt;?php $this->load->view('nav'); ?&gt;
  </div>  
  
  <div id="mainContent">
   &lt;?php $this->load->view($main);?&gt;
  </div>
    
    <br class="clearfloat" style="clear:both" />
  <div id="footer">
    <p>Copyright 2008 Your Company Inc</p>
  </div>

</div>
&lt;/body&gt;
&lt;/html&gt;


Many thanks for all your help again Smile




Theme © iAndrew 2016 - Forum software by © MyBB