CodeIgniter Forums
having trouble with controllers - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: having trouble with controllers (/showthread.php?tid=53361)

Pages: 1 2


having trouble with controllers - El Forum - 07-20-2012

[eluser]bradyrose[/eluser]
Hey guys. Ok.. so to start, im just barely proficient at php , so codeigniter has been a bit of a challenge.. I have appropriated code from a tutorial online to get my main page to display the index by default, and then display pages from within a folder in the views named 'pages' if there is a corresponding page name, ie, faq, about, account, etc.

ok.. so this was all well and working, however for some reason when i create a new public function, i can't get it to display to screen. ultimately my goal is so that I can load a third party app when i go to something particular like, index.php/pmsystem

perhaps im using the wrong path, or perhaps my previous code is somehow interfearing with the pubic function displaying... whatever it is I am stumped.


Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');


class Pages extends CI_Controller {

public function index()
{
  $this->load->view('index');
}




public function view($page = 'home')
    {

// show an error ir the page doesnt exist for some reason  
if ( ! file_exists('application/views/pages/'.$page.'.php'))
  {
  // Whoops, we don't have a page for that!
  show_404();
  }
  
//Capitalize the first letter of the title
$data['title'] = ucfirst($page);

// load all the helpers and libraries to be used  

$this->load->library('session');
$this->load->database();
$this->load->library('table');
$this->load->library('pagination');
$config['base_url'] = 'http://www.cashforbtc.com/index.php/feedback';
$config['total_rows'] = 300;
$config['per_page'] = 3;
$this->pagination->initialize($config);
$this->load->helper('url');
$this->load->helper('form');
$this->load->helper('captcha');

// load all the sections of the page

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

}

public function pmsystem()
{
echo "why does this not display?";
}

}



having trouble with controllers - El Forum - 07-20-2012

[eluser]InsiteFX[/eluser]
Code:
// Controller / Method
pages/pmsystem



having trouble with controllers - El Forum - 07-21-2012

[eluser]blekknajt[/eluser]
Check application/config/routes.php - I bet You have there (as in tutorial):
Code:
$route['(:any)'] = 'pages/view/$1';



having trouble with controllers - El Forum - 07-21-2012

[eluser]InsiteFX[/eluser]
The default controller is also set to pages/view

He should be using a new controller or add it to the pages pages/ page_view method.



having trouble with controllers - El Forum - 07-21-2012

[eluser]bradyrose[/eluser]
below is what it in my routes

Code:
$route['default_controller'] = 'pages/view';
$route['page/:any'] = 'pages/view/$1

$route['pages/pm'] = 'pages/pm';
$route['pages/pm/(:any)'] = 'pages/pm/$1';

it is not functioning as i would hope.

In my views folder i have a folder named pages, i would like it so that whenever i have a page such as www.cashforbtc.com/index.php/anypagename , it will go to that page in the pages folder if it exists.

In addition to this, I would like it if you go to index.php/pmsystem , that it would display (with the header and footer as other pages do) our pm system which is located at application/third_party/app_pmsystem


having trouble with controllers - El Forum - 07-21-2012

[eluser]InsiteFX[/eluser]
You need to place them above the others.
Note: Routes will run in the order they are defined. Higher routes will always take precedence over lower ones.
Code:
$route['pages/pm/(:any)'] = 'pages/pm/$1';
$route['pages/pm'] = 'pages/pm';

$route['page/:any'] = 'pages/view/$1
$route['default_controller'] = 'pages/view';



having trouble with controllers - El Forum - 07-21-2012

[eluser]bradyrose[/eluser]
I flipped the order in which they load, as it was posted previously it did not function at all, all pages i tried brought up blank screens. So i attempted to correct it on my own, and
as it is now, these are my routes

Code:
/$route['pages/pmsystem/(:any)'] = 'pages/pm/$1';
$route['index.php/pmsystem'] = '/pages/login.php';
$route['(:any)'] = 'pages/view/$1';  
$route['default_controller'] = 'pages/view';

Although im now back to functional for going to psges such as

http://www.cashforbtc.com/index.php/login

going to

http://www.cashforbtc.com/index.php/pmsystem

does not seem to route to /pages/login.php, or wherever i point it in the routes.






having trouble with controllers - El Forum - 07-21-2012

[eluser]InsiteFX[/eluser]
You do not add index.php to routes. I think you you need to read the CodeIgniter Users Guide on Routing.

CodeIgniter Users Guide - URI Routing



having trouble with controllers - El Forum - 07-22-2012

[eluser]bradyrose[/eluser]
I have read it, however i cannot say i understand it, I always try to read the user guide before posting. The reason i have been using index.php/pagename , is because it is all that is working for me. doing pages/pagename, has not been working.




having trouble with controllers - El Forum - 07-22-2012

[eluser]InsiteFX[/eluser]
Thats telling me that index.php is not fully removed.

To remove index.php
Code:
// Leave blank and CI will try to figure it out.
$config['base_url'] = '';

$config['index_page'] = '';

// .htaccess file in root with index.php

Options FollowSymLinks
Options -Indexes
DirectoryIndex index.php

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]