CodeIgniter Forums
Controller Naming Convention issue - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Model-View-Controller (https://forum.codeigniter.com/forumdisplay.php?fid=10)
+--- Thread: Controller Naming Convention issue (/showthread.php?tid=65353)



Controller Naming Convention issue - nkhan - 06-02-2016

I have complete a project In CI 3.0.6 , which is works fine in localhost. but when i uploaded it in subdoamin i am getting 

The demo.xyz.com page isn’t working

demo.xyz.com is currently unable to handle this request.


Path:applications/contorllers/Frontend.php

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

class 
Frontend extends Frontend_Controller {
 
   public function __construct ()
    {
        
parent::__construct();
        
$this->load->model('Banner_m');
     
      
    


Path:applications/model/Banner_M.php

PHP Code:
class Banner_M extends MY_Model
{
    protected 
$_table_name 'banners';
    protected 
$_order_by 'id desc';
    
    public function 
get_new ()
    {
        
$banner = new stdClass();
        
$banner->title '';
        
$banner->slug '';
        
$banner->target_url '';
        
$banner->banner_img '';
        
$banner->status'';
        
$banner->display_order'';
        return 
$banner;
    }
    
    


As i am debugging i got a point that is  the banner model ($this->load->model('Banner_m')) loaded in Frontend Controller.

Thanks.


RE: Controller Naming Convention issue - Tpojka - 07-11-2016

(06-02-2016, 06:51 AM)nkhan Wrote: I have complete a project In CI 3.0.6 , which is works fine in localhost. but when i uploaded it in subdoamin i am getting 

The demo.xyz.com page isn’t working

demo.xyz.com is currently unable to handle this request.


Path:applications/contorllers/Frontend.php

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

class 
Frontend extends Frontend_Controller {
 
   public function __construct ()
    {
        
parent::__construct();
        
$this->load->model('Banner_m');
     
      
    


Path:applications/model/Banner_M.php

PHP Code:
class Banner_M extends MY_Model
{
    protected 
$_table_name 'banners';
    protected 
$_order_by 'id desc';
    
    public function 
get_new ()
    {
        
$banner = new stdClass();
        
$banner->title '';
        
$banner->slug '';
        
$banner->target_url '';
        
$banner->banner_img '';
        
$banner->status'';
        
$banner->display_order'';
        return 
$banner;
    }
    
    


As i am debugging i got a point that is  the banner model ($this->load->model('Banner_m')) loaded in Frontend Controller.

Thanks.

I'd say you need index method or any other method to route request.
Next, your constructor method is not closed by curly bracket.
Third, `Banner_m !== Banner_M`. 
Advice would be to use ucfirst name for files/classes i.e. `Banner_m`.


RE: Controller Naming Convention issue - InsiteFX - 07-13-2016

If frontend controller is extended from a MY_Controller then place all of the frontend code into the MY_Controller as another class.

The MY_Controller should contain all controllers that are extended by the MY_Controller otherwise you need to use an autoloader

PHP Code:
/*
| Autoloader function
|
| Add to the bottom of your ./application/config/config.php
|
| All Class files should be placed in the ./application/core folder
|
| @author Brendan Rehman
| @param $class_name
| @return void
*/
function __autoloader($class_name)
{
    
/**
     * class directories - add more autoloading folders here… and you’re done.
     */
    
$directories = array(
        
APPPATH.'core/',
    );

    
// for each directory
    
foreach ($directories as $directory)
    {
        
// see if the file exsists
        
if (file_exists($directory.$class_name.'.php'))
        {
            
// only require the class once, so quit after to save effort (if you got more, then name them something else
            
require_once($directory.$class_name.'.php');

            return;
        }
    }
}

spl_autoload_register('__autoloader');