Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI 3.0.0: Controller within Controller bug caused by Sessions #3480

Closed
bartmika opened this issue Jan 14, 2015 · 7 comments
Closed

CI 3.0.0: Controller within Controller bug caused by Sessions #3480

bartmika opened this issue Jan 14, 2015 · 7 comments

Comments

@bartmika
Copy link

Hey,

In CodeIgniter 2.2.0 I was able to create a Controller object inside a Controller. In CodeIgniter 3.0.0-develop I am no longer able to do this because I get the error message: "Unable to locate the specified class: Session.php". Am I missing something? Here is my setup.

  1. Download 'CodeIgniter-Develop'

  2. Update autoloader.php & config.php & bbp_user_sessions table so it looks like this:

a) autoloader.php:

$autoload['drivers'] = array(
    'session'
); 

b) config.php:

$config['sess_driver']            = 'native';
$config['sess_valid_drivers']    = array();
$config['sess_cookie_name']        = 'bbp_user_sessions'; // Custom class.
$config['sess_expiration']        = 21600;               // 6 hours
$config['sess_expire_on_close']    = FALSE;
$config['sess_encrypt_cookie']    = TRUE;                // Use security
$config['sess_use_database']    = TRUE;                // Use database
$config['sess_table_name']        = 'bbp_user_sessions';
$config['sess_match_ip']        = FALSE;
$config['sess_match_useragent']    = TRUE;
$config['sess_time_to_update']    = 300; 

c) bbp_user_sessions table

CREATE TABLE `bbp_user_sessions` (
 `session_id` varchar(40) NOT NULL DEFAULT '0',
 `ip_address` varchar(45) NOT NULL DEFAULT '0',
 `user_agent` varchar(120) NOT NULL,
 `last_activity` int(10) unsigned NOT NULL DEFAULT '0',
 `user_data` text NOT NULL,
 PRIMARY KEY (`session_id`),
 KEY `last_activity_idx` (`last_activity`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  1. Don't forget to set the encryption key in config.php too. I used:
$config['encryption_key'] = 'Gargantia on the Verdurous Planet'; 
  1. Modify the 'Welcome.php' file that comes already with the framework to look like this:
<?php
/**
 * CodeIgniter
 *
 * An open source application development framework for PHP
 *
 * This content is released under the MIT License (MIT)
 *
 * Copyright (c) 2014 - 2015, British Columbia Institute of Technology
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * @package    CodeIgniter
 * @author    EllisLab Dev Team
 * @copyright    Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/)
 * @copyright    Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/)
 * @license    http://opensource.org/licenses/MIT    MIT License
 * @link    http://codeigniter.com
 * @since    Version 1.0.0
 * @filesource
 */
defined('BASEPATH') OR exit('No direct script access allowed');

class Welcome extends CI_Controller {

    /**
     * Index Page for this controller.
     *
     * Maps to the following URL
     *         http://example.com/index.php/welcome
     *    - or -
     *         http://example.com/index.php/welcome/index
     *    - or -
     * Since this controller is set as the default controller in
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see http://codeigniter.com/user_guide/general/urls.html
     */
    public function index()
    {
        $this->_load_home_controller();

        $this->load->view('welcome_message');
    }

    private function _load_home_controller()
    {
        include(APPPATH.'controllers/Home.php');
        $controller = new Home();
        $controller->index();
    }

}

/* End of file welcome.php */
/* Location: ./application/controllers/Welcome.php */ 
  1. Create a 'home.php' controller and fill it with the following contents:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Home extends CI_Controller {

    /**
     * Index Page for this controller.
     *
     * Maps to the following URL
     *         http://example.com/index.php/welcome
     *    - or -
     *         http://example.com/index.php/welcome/index
     *    - or -
     * Since this controller is set as the default controller in
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see http://codeigniter.com/user_guide/general/urls.html
     */
    public function index()
    {
        echo "Testing: Home Page";

        $this->load->view('welcome_message');
    }
}

/* End of file Home.php */
/* Location: ./application/controllers/Home.php */ 
  1. Load up webapp through your Nginx/Apache/Lighttpd/etc and you'll see the same error message.
@bartmika
Copy link
Author

Note: There is also a forum thread on this too: http://forum.codeigniter.com/thread-744.html

@narfbg
Copy link
Contributor

narfbg commented Jan 14, 2015

  1. Don't copy-paste forum threads just because you don't get the answer that you're looking for.
  2. This is not a bug - a controller insider a controller has never been a feature supported by CI.
  3. Whatever problem you're having, it's not caused by the Session class.
  4. You haven't followed the upgrade instructions.

@narfbg narfbg closed this as completed Jan 14, 2015
@bartmika
Copy link
Author

  1. Sorry
  2. May you support it?
  3. Well what is it then? How do I fix it?
  4. https://www.chuongduong.net/ci3/installation/upgrade_300.html

@narfbg
Copy link
Contributor

narfbg commented Jan 14, 2015

I already told you yesterday that we don't provide support here. Keep it on the forums.

@jim-parry
Copy link
Contributor

@RunAsNigga What does this have to do with the current thread???
If you have an issue, raise it on the forum, thanks.

@jim-parry
Copy link
Contributor

@RunAsNigga It sounds like you have a mismatched version of the system folder.
In CI3.0.0, the session library is in system/libraries/Session/Session.php

@bcit-ci bcit-ci locked and limited conversation to collaborators May 29, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@narfbg @jim-parry @bartmika and others