Welcome Guest, Not a member yet? Register   Sign In
Controllers under subfolder
#11

It should not be put inside the Libraries folder it's not a Library Class it's a Controller Class.
What did you Try? What did you Get? What did you Expect?

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

(07-02-2016, 01:02 AM)sv3tli0 Wrote: Remember that MY_ classes existed in the old CI versions because there were no namespaces.. Now in CI 4 you are able simply to create App/Controllers/Controller and to use it from your other controllers..
The era of MY_ logic is over.

Yes. I agree. CI-4 have different phylosophy than CI-3.
Reply
#13

(This post was last modified: 07-02-2016, 04:47 AM by arma7x.)

(07-02-2016, 01:02 AM)sv3tli0 Wrote: Remember that MY_ classes existed in the old CI versions because there were no namespaces.. Now in CI 4 you are able simply to create App/Controllers/Controller and to use it from your other controllers..
The era of MY_ logic is over.
The term of "MY_Controller" or "custom controller" is only example for controller extends to \CodeIgniter\Controller and it is intended to be extends for any controller that having common behaviour/task to be done before it executed or some method(like AdminController verify user role before give access to any users).

(07-02-2016, 03:19 AM)InsiteFX Wrote: It should not be put inside the Libraries folder it's not a Library Class it's a Controller Class.
Yes, it not recommended to put inside libraries folder. The "custom controller" should be organize in one folder. And controllers folder should only contain controller visitable by user.
Keep calm.
Reply
#14

(This post was last modified: 07-02-2016, 04:29 AM by arma7x.)

(07-02-2016, 03:40 AM)titounnes Wrote:
(07-02-2016, 01:02 AM)sv3tli0 Wrote: Remember that MY_ classes existed in the old CI versions because there were no namespaces.. Now in CI 4 you are able simply to create App/Controllers/Controller and to use it from your other controllers..
The era of MY_ logic is over.

Yes. I agree. CI-4 have different phylosophy than CI-3.

Yes, absolutely different philosophy. The MY_classes will extends the base classes and each classes only have one job/situation to handle. But for controller you need multiple classes to handle different type of situation such as AdminController, PublicControler and etc. What I did in CI3 is, by having multiple class in one MY_Controller.php(also can be done by other way). As in CI4, thanks to namespace.
Keep calm.
Reply
#15

(07-02-2016, 02:06 AM)arma7x Wrote:
(07-01-2016, 10:07 PM)fromberg Wrote: Hi All,

thanks for your feedback and suggestions.

I have tried all but still the same problem.  I downloaded the latest CI 4 from repository.

My environment is Windows.

I will keep trying.  If any additional tip, would be highly appreciated.

Thanks and regards,

This is controller file inside sub-folder Ajax in Controller folder;
PHP Code:
<?php namespace App\Controllers\Ajax;

class 
Test extends \CodeIgniter\Controller
{

    public function 
index()
    {
 
               echo 'hi Im test in ajax sub folder';
    }

    
//--------------------------------------------------------------------



Edit your route file, /application/Config/Routes.php by adding:
PHP Code:
$routes->add('ajax/test''Test::index', ['namespace' => 'App\Controllers\Ajax']); 

It's works for me. Using CI4, if you namespace the controller, you have to set $routes->setDefaultNamespace('App\Controllers'); and define $routes->add() for each controller(Having 404NotFound problem if I’m did not do this).

Hi arma7x,

I highly appreciate your help, it works now.

Just curious, should this be done like this?  Shouldn't it be working automatically?

Thanks and regards,
Reply
#16

(This post was last modified: 07-02-2016, 07:55 AM by arma7x.)

(07-02-2016, 07:24 AM)fromberg Wrote:
(07-02-2016, 02:06 AM)arma7x Wrote:
(07-01-2016, 10:07 PM)fromberg Wrote: Hi All,

thanks for your feedback and suggestions.

I have tried all but still the same problem.  I downloaded the latest CI 4 from repository.

My environment is Windows.

I will keep trying.  If any additional tip, would be highly appreciated.

Thanks and regards,

This is controller file inside sub-folder Ajax in Controller folder;
PHP Code:
<?php namespace App\Controllers\Ajax;

class 
Test extends \CodeIgniter\Controller
{

 public function 
index()
 {
 
               echo 'hi Im test in ajax sub folder';
 }

 
//--------------------------------------------------------------------



Edit your route file, /application/Config/Routes.php by adding:
PHP Code:
$routes->add('ajax/test''Test::index', ['namespace' => 'App\Controllers\Ajax']); 

It's works for me. Using CI4, if you namespace the controller, you have to set $routes->setDefaultNamespace('App\Controllers'); and define $routes->add() for each controller(Having 404NotFound problem if I’m did not do this).

Hi arma7x,

I highly appreciate your help, it works now.

Just curious, should this be done like this?  Shouldn't it be working automatically?

Thanks and regards,

Read explanation here from kilishan.

But only controller with namespace(if I'm not wrong) you need to define route;
PHP Code:
$routes->add('ajax/test''Test::index', ['namespace' => 'App\Controllers\Ajax']); 
For controller under subfolder without using namespace, I didn’t find any information in documentation. So, by using namespace able to solve this problem.
Keep calm.
Reply
#17

Thanks to this thread I have identified a couple of issues with the Routing. In part, was my original assumptions turned out incorrect - I thought the two philosophies would be used separately. Either you had a namespaced controller that was specified in the routes file, or the auto-routed version to stuff in the controller folder, where the classes were in the global namespace.

Listening to your feedback, I've gone back and fixed one issue that was keeping non-namespaced controllers from being auto-routed last night. Though I'm trying to find a nice way to make it testable currently. Smile And I will be working on making auto-routing working with namespaces - as long as that namespace lands in the controllers folder, anyway.

So - thanks for the feedback! And, have patience, we'll work the bugs out. Smile
Reply
#18

(This post was last modified: 07-10-2016, 04:59 AM by InsiteFX.)

The person that is having trouble on a windows system you need to setup ENVIRONMENT VARIABLES in the windows control panel you may also need to edit the C:\Windows\System32\drivers\etc\host

host is a file that defines the windows localhost sometime the 127.0.0.1 is remarked out and you need to un-remark it.

You can use notepad to edit the file. Make sure you save it afterwards and restart your servers etc;
What did you Try? What did you Get? What did you Expect?

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

(This post was last modified: 07-10-2016, 06:34 AM by arma7x.)

(07-10-2016, 04:59 AM)InsiteFX Wrote: The person that is having trouble on a windows system you need to setup ENVIRONMENT VARIABLES in the windows control panel you may also need to edit the C:\Windows\System32\drivers\etc\host

host is a file that defines the windows localhost sometime the 127.0.0.1 is remarked out and you need to un-remark it.

You can use notepad to edit the file. Make sure you save it afterwards and restart your servers etc;

Or use PHP: Built-in web server "php -S 127.0.0.1:xxxx -t /path/to/public" for those having problem when using base_url(), site_url() and current_url(). The only way to visit webapp in browser, the URL should be http://127.0.0.1:xxxx not http://127.0.0.1/path/to/public
Keep calm.
Reply
#20

@ arma7x

I do not get your point on this because http://127.0.0.1/path/to/public Works just fine on my Windows system and has for years but now I use VirtualHosts
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB