CodeIgniter Forums
can't send parameter to admin function - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: can't send parameter to admin function (/showthread.php?tid=545)



can't send parameter to admin function - valencia - 12-16-2014

hi all, I'am very new with CI,

I try to set up CI with Bootstrap themplate, and admin, bootstrap front page works fine and I set up admin page to, but couldn't figure out to change pages in admin theme, I know it's sounds confiused but please try to help me understand this.

here is what I have router page
PHP Code:
$route['(:any)'] = 'pages/view/$1';
$route['default_controller'] = 'pages/view';
$route['404_override'] = '';

$route['admin/(:any)'] ='admin/admin_pages/$1';
$route['admin'] = 'admin/admin_pages'

and this is my admin_pages class

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

    Class 
Admin_pages extends CI_Controller{
    
       public function 
__construct(){
       
            
parent::__construct();
            
// Your own constructor code  
            
       
}
    
        public function 
index(){
        
            
$this->admin_pages();
        
        }
        
        
        public function 
admin_pages($admin_page 'dashboard'){
        
        if(!
file_exists('application/views/admin/ad_pages/'.$admin_page.'.php')) {
        
            
show_404();
        
        }

            
$data['title'] = $admin_page;
            
$this->load->view('admin/ad_template/ad_header',$data);
            
$this->load->view('admin/ad_template/ad_nav');
            
$this->load->view('admin/ad_pages/'.$admin_page,$data);
            
$this->load->view('admin/ad_template/ad_footer');
        } 
    
    } 

and this my pages class

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

class 
Pages extends CI_Controller {
    
    public function 
index() {
 
       
## call the pages dynamicly
       
$this->view(); 
        
    }
    
    
    public function 
view($page "home") {
    
        
$this->load->helper('url');
        
$base_url base_url();
        if(!
file_exists('application/views/pages/'.$page.'.php')) {
        
            
show_404();
        
        }
      
        
## this gives the title to every page with 
        ## ucfirst() this makes firts letter big 
        
$data['title'] = ucfirst($page); 

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


I'am working on localhost and all my codes is inside the folder codeIgniter

now when I write in url
Code:
http://localhost/codeIgniter/

It's opening the home page,it's ok, fine, and if I change url to this

Code:
http://localhost/codeIgniter/about

this works too.

if I want to go to admin page I do this

Code:
http://localhost/codeIgniter/admin/

this opens the admin page dashboard

if I want to change this to tables

Code:
http://localhost/codeIgniter/admin/tables

this give me error "page not found"

but if I change in admin_pages method'2 parameter to tables this works.

question is why I can't send parameter to my admin_pages method


RE: can't send parameter to admin function - Rufnex - 12-16-2014

Can you show your Admin.php Controller.


RE: can't send parameter to admin function - valencia - 12-16-2014

Should I have one own controller for admin, do you mean ?
My folder looks like this
Application
Controllers
PagesYyyyyyhyyby
Admin_pages

And in admin_pages I have this to call pages from view
I have the code up there under admin_pages.
I'm on mobile right now sorry.


RE: can't send parameter to admin function - Rufnex - 12-16-2014

Its a good design to have the admin stuff away from the others. So a own admin controller should be. In your example you should have

http://localhost/codeIgniter/admin/tables -> /Controllers/Admin.php

Right now you have a Admin_pages.php Controller .. right? and with :any you will call a method ...

PHP Code:
$route['admin/(:any)'] ='admin/admin_pages/$1';
$route['admin'] = 'admin/admin_pages'

If you go to http://localhost/codeIgniter/admin/tables you call the method tables in your controller.


RE: can't send parameter to admin function - valencia - 12-16-2014

I think I understand little bit now, I will try that when I'm at the home. I will be back with result, thank you Smile


RE: can't send parameter to admin function - InsiteFX - 12-16-2014

Routes are Controller/Method

Also as stated in some of my other posts the (:any) is a catch all route and has to be the last route in your routes.php file.

No route will ever run after the $route['(:any)']

PHP Code:
$route['default_controller'] = 'pages/view';

$route['404_override'] = '';

$route['admin'] = 'admin/admin_pages'; 
$route
['admin/(:any)'] ='admin/admin_pages/$1';

$route['(:any)'] = 'pages/view/$1'
This is the correct way to form your routes using the (:any)


RE: can't send parameter to admin function - valencia - 12-16-2014

i just removed this
from this
PHP Code:
$route['(:any)'] = 'pages/view/$1';
$route['default_controller'] = 'pages/view';
$route['404_override'] = '';

$route['admin/(:any)'] ='admin/admin_pages/$1';
$route['admin'] = 'admin/admin_pages'

to this


PHP Code:
$route['default_controller'] = 'pages/view';
$route['404_override'] = '';

$route['admin'] = 'admin/admin_pages/call_admin_pages/'

and in url writing like this
Code:
base_url and  admin/admin_pages/call_admin_pages/tables or charts

and this is sending parameters to my method and its works


RE: can't send parameter to admin function - valencia - 12-16-2014

#insiteFX

Thank You, I did't know it, but I tried still can't send parametre to class admin_pages method to call other pages.
my folders looks like this,


Code:
application/
        config/
        controllers/
            admin/
                 admin_pages.php
        models/
            something.php
        views/
            admin/
                ad_pages/
                    forms.php
                    tables.php
                charts.php                    
                dashboard.php
                ad_template/
                    header.php
                    nav.php
            footer.php
            pages/
                home.php
                about.php
            templates/
                header.php
                nav.php
        footer.php

Where do I make wrong?


RE: can't send parameter to admin function - InsiteFX - 12-17-2014

You can always use the CodeIgniter URI Class to get the parameters for the different segments.

PHP Code:
$this->uri->segment(n

SEE: The CodeIgniter URI Class in the Users Guide.

That is what I always use to get different passed in parameters.

In your case it would be uri segment (3)