Welcome Guest, Not a member yet? Register   Sign In
Router
#1

Hello everybody.
I want to replace CI 2.1 to CI 3.1
But i have a problem. I can't transfer to the function an argument from router.

Router:
PHP Code:
$route['default_controller'] = 'pages/show/ukr'

"ukr" - i can't transfer to the function in the class.!?
Class:
PHP Code:
class Pages extends CI_Controller{
    
    
public function __construct(){
      parent::__construct();
      $this->load->model('pages_model');
    }
    
    
public function show($page_id){   
      $data
=array();
      $data['main_info']=$this->pages_model->get($page_id);
        $name='pages/mainpage';
        $this->display_lib->user_page($data,$name);                          
    
}

What is it.!? Huh
This is as it should be?
Reply
#2

disclaimer - i'm just writing this out and did not test this so i could be wrong -
but i think you could just give page id a default value

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


PHP Code:
public function show($page_id 'ukr' ){ 
Reply
#3

(This post was last modified: 09-21-2016, 11:42 AM by InsiteFX.)

PHP Code:
$route['default_controller'] = 'welcome'

Note: You can NOT use a directory as a part of this setting!

CodeIgniter Users Guide - URI Routing

Use a Landing Page.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

(09-21-2016, 11:15 AM)cartalot Wrote: disclaimer - i'm just writing this out and did not test this so i could be wrong -
but i think you could just give page id a default value

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


PHP Code:
public function show($page_id 'ukr' ){ 

Yes i could...
It just worked in CI 2.1 but does not working in CI 3.1
Reply
#5

(09-21-2016, 11:40 AM)InsiteFX Wrote:
PHP Code:
$route['default_controller'] = 'welcome'

Note: You can NOT use a directory as a part of this setting!

CodeIgniter Users Guide - URI Routing

Use a Landing Page.

It's about my case?)
Reply
#6

(09-21-2016, 11:40 AM)InsiteFX Wrote: Note: You can NOT use a directory as a part of this setting!

Which is definitely true, but in this case the controller is not in a directory.
Reply
#7

(This post was last modified: 09-21-2016, 05:41 PM by wolfgang1983.)

If you need to use subfolder in CI3 for default_controller you need to have a Custom MY_Router.php

core/MY_Router.php

Link https://github.com/wolfgang1983/CI3-defa...sub_folder

controllers / pages / Welcome.php


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


PHP Code:
<?php
 
class MY_Router extends CI_Router {
 
   protected function _set_default_controller() {
 
        
        if 
(empty($this->default_controller)) {
 
           
            show_error
('Unable to determine what should be displayed. A default route has not been specified in the routing file.');
 
       }
 
       // Is the method being specified?
 
       if (sscanf($this->default_controller'%[^/]/%s'$class$method) !== 2) {
 
           $method 'index';
 
       }
 
        
        
// This is what I added, checks if the class is a directory
 
       ifis_dir(APPPATH.'controllers/'.$class) ) {
 
            
            
// Set the class as the directory
 
           
            $this
->set_directory($class);
 
           
            
// $method is the class
 
           
            $class 
$method;
 
           
            
// Re check for slash if method has been set
 
           
            if 
(sscanf($method'%[^/]/%s'$class$method) !== 2) {
 
               $method 'index';
 
           }
 
       }
 
        
        if 
( ! file_exists(APPPATH.'controllers/'.$this->directory.ucfirst($class).'.php')) {
 
           
            
// This will trigger 404 later
 
           
            return
;
 
       }
 
       $this->set_class($class);
 
       $this->set_method($method);
 
       // Assign routed segments, index starting from 1
 
       $this->uri->rsegments = array(
 
           1 => $class,
 
           2 => $method
        
);
 
       log_message('debug''No URI present. Default controller set.');
 
   }

There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply
#8

Thanks guys for halp, but i will stay at CI 2.1
There one more error.
Don't work this SQL request in CI 3.1.!?
PHP Code:
$sql "select * from (select * from net_euro where begin_ip<=$int order by begin_ip desc limit 1) as t where end_ip>=$int";
$result mysql_query($sql); 
Variable "$result" is empty.
Perhaps this is not the end. Confused
Reply
#9

Use MySQLi
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#10

(09-23-2016, 01:35 PM)Ljubin Wrote: Thanks guys for halp, but i will stay at CI 2.1
There one more error.
Don't work this SQL request in CI 3.1.!?
PHP Code:
$sql "select * from (select * from net_euro where begin_ip<=$int order by begin_ip desc limit 1) as t where end_ip>=$int";
$result mysql_query($sql); 
Variable "$result" is empty.
Perhaps this is not the end. Confused

This may help $query = $this->db->query("YOUR QUERY");

http://www.codeigniter.com/user_guide/da...ult-arrays
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB