• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Code Modules

#1
Earlier, I already wrote about problems with module code.
And again, I experienced deja vu, what was before now does not work.
I get an error at page request ex.com/node

Quote:We seem to have hit a snag. Please try again later...
ex.com\app\Config\Autoload.php
PHP Code:
class Autoload extends \CodeIgniter\Config\AutoloadConfig
{
    public $psr4 = ['Modules\Node' => ROOTPATH.'Modules/Node']; 
ex.com\modules\Node\Controllers\Node.php
PHP Code:
<?php namespace Modules\Node\Controllers;

class 
Node extends \CodeIgniter\Controller
{
    public function index()
    {
        echo "You see me?";
    }

ex.com\app\Config\Routes.php
PHP Code:
$routes->setDefaultNamespace('App\Controllers');
//$routes->setDefaultController('Node');
//$routes->setDefaultMethod('index');
$routes->setAutoRoute(true);
$routes->discoverLocal(true);
$routes->add('node''Modules\Node\Controllers\Node::index'); 

I apologize for the code but it is very short to upload it somewhere else, and thanks for your tolerance =)
Reply

#2
What error are you receiving?

Sounds like you need to set environment to development so you can see errors.
Support Development  • Practical CodeIgniter 3  • Vulcan - CLI Tools for CI4
Reply

#3
Here you have a back slash then a forward slash.

PHP Code:
public $psr4 = ['Modules\Node' => ROOTPATH.'Modules/Node']; 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#4
(06-24-2019, 03:33 PM)InsiteFX Wrote: Here you have a back slash then a forward slash.

PHP Code:
public $psr4 = ['Modules\Node' => ROOTPATH.'Modules/Node']; 

The '\' referencing a namespace, and the '/' is referencing a file path, so this is correct. I don't know if it's correct other than the context of namespaces and file paths as far as the rest of the script is concerned.
Reply

#5
(06-24-2019, 09:54 AM)kilishan Wrote: What error are you receiving?

Sounds like you need to set environment to development so you can see errors.

Controller or its method is not found: \Modules\Node\Controllers\Node::index

but in my:
ex.com\modules\Node\Config\Routes.php
PHP Code:
$routes->group('node', ['namespace' => 'Modules\Node\Controllers'], function($routes)
{
    $routes->get('/',    'Node::index');
}); 

ex.com\app\Config\Routes.php
PHP Code:
$routes->add('node''Modules\Node\Controllers\Node::index'); 
Something of this was supposed to work.
Reply

#6
I have my Admin module setup like this and it works fine.

PHP Code:
// Autoload.php
'Insitefx\Admin'    => ROOTPATH.'Insitefx\Admin'  // Our Admin Module.

// Routes.php
$routes->group('', ['namespace' => 'Insitefx\Admin\Controllers'], function($routes)
{
 
   $routes->get('admin''Admin::index');
}); 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#7
(06-25-2019, 05:33 AM)InsiteFX Wrote: I have my Admin module setup like this and it works fine.

PHP Code:
// Autoload.php
'Insitefx\Admin'    => ROOTPATH.'Insitefx\Admin'  // Our Admin Module.

// Routes.php
$routes->group('', ['namespace' => 'Insitefx\Admin\Controllers'], function($routes)
{
 
   $routes->get('admin''Admin::index');
}); 

You Routes.php in app/Config or Admin/Config ?

P.S

I changed backslash than a forward slash but it did not help me.
Reply

#8
app config or in my module it works both ways for me.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#9
So i understanding...

1. ex.com\app\Config\Autoload.php (in __construct) write any namespaces... (Don't change name of the 'CodeIgniter')
PHP Code:
$psr4 = ['Any' => ROOTPATH.'Anymodules'];
/*
 * 'Anymodules\Any'=> ROOTPATH.'Anymodules/Any'
 *  It is advisable to respect the register as in the folder names.
 *  But usually it is forgiven =)
 */ 
2. ex.com\app\Config\Routes.php
PHP Code:
$routes->get('any''Anymodules\Any\Controllers\Any::index'); 
3. ex.com\anymodules\Any\Controllers\Any.php

PHP Code:
<?php namespace Anymodules\Any\Controllers;

class 
Any extends \CodeIgniter\Controller
{
 
   public function index()
 
   {
 
       echo "You Any views!";
 
   }
?>
4. in browser ex.com/any and Enjoy the result.

It works !
Sorry to bother you, everything turned out to be easy. I hope this will help others in the future.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
2 Guest(s)


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