• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MY_config.php and MY_url_helper.php not being included in Linux

#1
[eluser]cotsweb[/eluser]
Hi,
I am working on my first CI site so please forgive me if I am being stupid.

Part of my site is to be SSL protected so I have followed Mohammad Sajjad Hossain's useful guide

It all works fine on my development machine (Windows XP) but when I move to my testing machine (Linux - Ubuntu Server) it doesn't include the necessary modules. I suspect it is something to do with the case of a filename but I can't see it; I have used get_included_files() to check it and I get the following on windows;
Code:
C:\sites\stc\public_html\index.php
C:\sites\stc\system\core\CodeIgniter.php
C:\sites\stc\system\core\Common.php
C:\sites\stc\application\config\constants.php
C:\sites\stc\system\core\Benchmark.php
C:\sites\stc\application\config\config.php
C:\sites\stc\system\core\Hooks.php
C:\sites\stc\system\core\Config.php
C:\sites\stc\application\core\MY_config.php
C:\sites\stc\system\core\Utf8.php
C:\sites\stc\system\core\URI.php
C:\sites\stc\system\core\Router.php
C:\sites\stc\application\config\routes.php
C:\sites\stc\system\core\Output.php
C:\sites\stc\application\config\mimes.php
C:\sites\stc\system\core\Security.php
C:\sites\stc\system\core\Input.php
C:\sites\stc\system\core\Lang.php
C:\sites\stc\system\core\Controller.php
C:\sites\stc\application\controllers\pages.php
C:\sites\stc\system\core\Loader.php
C:\sites\stc\application\config\autoload.php
C:\sites\stc\application\helpers\MY_url_helper.php
C:\sites\stc\system\helpers\url_helper.php
C:\sites\stc\application\views\templates\html_header.php
C:\sites\stc\application\views\templates\google_site_search.php
C:\sites\stc\application\views\templates\header.php
C:\sites\stc\application\views\templates\sidebar.php
C:\sites\stc\application\views\templates\addthis.php
C:\sites\stc\application\views\pages\home.php
C:\sites\stc\application\views\templates\html_footer.php

And the following on Linux;
Code:
/var/www/stc/public_html/index.php
/var/www/stc/system/core/CodeIgniter.php
/var/www/stc/system/core/Common.php
/var/www/stc/application/config/constants.php
/var/www/stc/system/core/Benchmark.php
/var/www/stc/application/config/testing/config.php
/var/www/stc/system/core/Hooks.php
/var/www/stc/system/core/Config.php
/var/www/stc/system/core/Utf8.php
/var/www/stc/system/core/URI.php
/var/www/stc/system/core/Router.php
/var/www/stc/application/config/routes.php
/var/www/stc/system/core/Output.php
/var/www/stc/application/config/mimes.php
/var/www/stc/system/core/Security.php
/var/www/stc/system/core/Input.php
/var/www/stc/system/core/Lang.php
/var/www/stc/system/core/Controller.php
/var/www/stc/application/controllers/pages.php
/var/www/stc/system/core/Loader.php
/var/www/stc/application/config/autoload.php
/var/www/stc/system/helpers/url_helper.php
/var/www/stc/application/views/templates/html_header.php
/var/www/stc/application/views/templates/google_site_search.php
/var/www/stc/application/views/templates/header.php
/var/www/stc/application/views/templates/sidebar.php
/var/www/stc/application/views/templates/addthis.php
/var/www/stc/application/views/pages/home.php
/var/www/stc/application/views/templates/html_footer.php

The linux version isn't including either application/core/MY_Config.php or application/helpers/MY_url_helper.php

But I can't see why, can anyone else?

I will include the code in a reply to this post because I don't seem able to put it all in one post or attach files.

#2
[eluser]cotsweb[/eluser]
I have created 2 modules;
application/core/MY_Config.php
Code:
<?php
/**
* MY_Config.php.
* Created by: cotsweb
* Created on: 18/09/12
*
* See http://sajjadhossain.com/2010/08/18/ssl-https-urls-and-codeigniter-extending-the-core/
* Name changed to match case of original class
*/

class MY_Config extends CI_Config
{
/*  function MY_Config()
    {
     parent::CI_Config();
    }
*/
    function secure_site_url($uri = '')
    {
        if (is_array($uri))
        {
            $uri = implode('/', $uri);
        }

        if ($uri == '')
        {
            return $this->slash_item('secure_base_url').$this->item('index_page');
        }
        else
        {
            $suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix');
            return $this->slash_item('secure_base_url').$this->slash_item('index_page').preg_replace("|^/*(.+?)/*$|", "\\1", $uri).$suffix;
        }
    }
}
And application/helpers/MY_url_helper.php
Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
* my_url_helper.php.
* Created by: cotsweb
* Created on: 18/09/12
*
* based on http://sajjadhossain.com/2010/08/18/ssl-https-urls-and-codeigniter-extending-the-core/
*/
if( ! function_exists('secure_site_url') )
{
    function secure_site_url($uri = '')
    {
        $CI =& get_instance();
        return $CI->config->secure_site_url($uri);
    }
}

if( ! function_exists('secure_base_url') )
{
    function secure_base_url()
    {
        $CI =& get_instance();
        return $CI->config->slash_item('secure_base_url');
    }
}

if ( ! function_exists('secure_anchor'))
{
    function secure_anchor($uri = '', $title = '', $attributes = '')
    {
        $title = (string) $title;

        if ( ! is_array($uri))
        {
            $secure_site_url = ( ! preg_match('!^\w+://! i', $uri)) ? secure_site_url($uri) : $uri;
        }
        else
        {
            $secure_site_url = secure_site_url($uri);
        }

        if ($title == '')
        {
            $title = $secure_site_url;
        }

        if ($attributes != '')
        {
            $attributes = _parse_attributes($attributes);
        }

        return '<a href="' . $secure_site_url . '" rel="nofollow">' . $title . '</a>';    }
}

if ( ! function_exists('secure_redirect'))
{
    function secure_redirect($uri = '', $method = 'location', $http_response_code = 302)
    {
        switch($method)
        {
            case 'refresh'    : header("Refresh:0;url=".secure_site_url($uri));
            break;
            default           : header("Location: ".secure_site_url($uri), TRUE, $http_response_code);
            break;
        }
        exit;
    }
}

Can anyone see my mistake?

#3
[eluser]cotsweb[/eluser]
I finally figured this out.

The file names were indeed the wrong case on the test server. On my development machine they were MY_... but on the testing server they had somehow become my_... which means that CI wasn't including them.
I'm not sure how the filenames were changed. I may have something set wrong in PHPstorm or in Git.

I logged on to the server and checked the names manually to find the problem, it was easy to fix but not so easy to find.

#4
[eluser]TWP Marketing[/eluser]
I don't use the 'MY_...' prefix on my custom config files.
In your application/config/config.php file, you can autoload customer config like this:

Code:
/*
| -------------------------------------------------------------------
|  Auto-load Config files
| -------------------------------------------------------------------
| Prototype:
|
| $autoload['config'] = array('config1', 'config2');
|
| NOTE: This item is intended for use ONLY if you have created custom
| config files.  Otherwise, leave it blank.
|
*/

$autoload['config'] = array('another_config');

#5
[eluser]cotsweb[/eluser]
@TW Marketing - That's a useful hint thanks.

My next problem was to persuade Git to change the case of the file names, by default it doesn't seem to notice the case of the filename so even if I change it on my development machine the change doesn't get pushed to testing or live.

I found this useful post on changing the case of the filename in Git. Which pointed me in the right direction.

Windows thinks that MY_Config.ph and my_config.php are the same file so that is why you have to rename in 2 steps. It worked for me.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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