• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
can't send parameter to admin function

#1
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
Reply

#2
Can you show your Admin.php Controller.

Reply

#3
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.
Reply

#4
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.

Reply

#5
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
Reply

#6
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)
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#7
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
Reply

#8
#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?
Reply

#9
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)
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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