Zend 2 - Default Controller route (ZF2) - model-view-controller

I'm working on a website that have virtual hosts, like xyz.com, asd.com and so on.
I use Hostname route like ":controller.com", so it routes me to the specific controller.
I created a defaultController to a default behavior and I extended xyzController and asdController from that, so I only modify that I really want.
The problem is that, how can I create my DefaultController to be really default :) I mean, if I haven't created a controller for the specific route (forexample: xyzController for xyz.com), then I don't want to get a Fatal Error like
"Fatal error: Class 'aaaa\Controller\asdController' not found in /var/www/samba/aaaa/www/src/site/vendor/ZF2/library/Zend/ServiceManager/AbstractPluginManager.php on line 177"
Would be better if it route me to defaultController immediately.
I was thinking about the view_manager's templates like 'not_found_template'. That would be great if not_found_controller would exist :)
Is it possible to do somehow?

Related

Why am I getting Target class [Controller Name] does not exist

I always have this message:
Illuminate\Contracts\Container\BindingResolutionException
Target class [MessagesController] does not exist.
On some route and URL requests,
MessagesController however is not contained on my route web files, and in any of my controllers.
Can someone explain to me why the Controller class gives a warning?
Target class [MessagesController] does not exist.
Follow-up question, is there a way I can remove an unused controller by an artisan command?
The solution I made for this is to import MessagesController class, I'm so dumb I didn't figured it out.
On route:
use App\Https\Controller\MessagesController;

My Laravel Routes Are Not Working Error 404

I am working on an existing laravel project. Problem is whenever I create a new route the new route does not function. Also I am not receiving this error
GET http://localhost/khawaja%20sons/khawjapos.unialsolutions.com/public/products/warehouse 404 (Not Found).
Routes
ProductController
link from where I am using the route
Output
You have a two option how to use routes after you are set them:
first one :
Link
You have tried this method but, you need to remove asset function, because asset function return path to public folder
The second way to use route and the way I recommend is to use route names
Link
I recommend this way, because if you change the path in future, your change will be applied to everywhere you use route name, you don't need to be worry is route will work
I have tried both options before. Both are giving the same error

How to attach middleware to an existing named route from a package in laravel 5?

I'm trying to extend an existing application without modifying its source code.
The application has a named route called wizard-add.
Is there a way to register \MyPackage\MyMiddleware with the existing route?
I tried attaching it via Route::getRoutes()->getByName('wizard-add')->middleware(\MyPackage\MyMiddleware::class); but since packages are registered before the routes are read, Route::getRoutes() returns an empty collection.
Thank you!
Since I didn't find a way to solve this, I extended the app's controllers and put my logic inside.
namespace MyPackage\Controllers;
use App\Controllers\WizardController;
class MyPackageWizardController extends WizardController { ... }
and then in my service provider's register() method:
$this->app->bind(WizardController::class, MyPackageWizardController::class);
So everytime the app attempts to instantiate WizardController, it instantiates MyPackageWizardController instead. I don't know if there are any drawbacks but so far this has been working perfectly for me.

call codeigniter API from outside the framework

I have an iPhone application which perform calls to an API developed with codeigniter. Since I am new to the framework, I want to know where such API are normally located ? The url requested from the iPhone application to the API is the following:
http://example.com/site/welcome/admin/api/processingdocuments/
I got a look on the application/libraries folder and there is a bench of php files like rest.php and REST_Controller.php. Are these the files I am looking for? Since the URL above doesn't point to specific file, how to know which API is being called? Thank you in advance.
When using Phil Sturgeon's CodeIgniter Restserver (which is what it seems you are using), you set up a controller within application/controllers directory and extend his class.
Let's say you call your controller Foobar, and it looks like this:
class Foobar extends Rest_Controller {
//... your methods here
}
In this case, you will access this endpoint at http://example.com/foobar
The URL references your controllers, and not the Rest_Controller directly.
URLs look like this:
http://example.com/{controller}/{method}/{param1}/{param2}/.../{paramN}
If method is not specified, it defaults to index()
Further, the Restserver allows you to map methods to HTTP request methods. Such that
GET example.com/foobar will map to the method index_get()
POST example.com/foobar will map to the method index_post()
..and so on.
I highly recommend you read the documentation
In your example, you would expect the controller that is being called to be located at application/controllers/site.
However, this might have been modified using htaccess rewrite rules (check for a .htaccess file), or via redefined CI routes (check application/config/routes.php).
If all else fails:
Under default configurations, that is where you should find them, however, CI is very malleable with routes and it is hard to say where they might be. Your best bet would be to grep the directory for the words extends Rest_Controller since wherever the controllers are, they would be extending that class.

PHPUnit + CodeIgniter multiple objects with same name

I currently test my CodeIgniter app with phpunit by using CIUnit (https://bitbucket.org/kenjis/my-ciunit). The problem is that I have multiple controllers with the same name. I have a controller in the root controller directory named "Blog" and I have a controller called "Blog" in the controller/ajax/ directory.
The reason is to seperate all ajax requests from the main controller.
When I am running tests on both files, I get the following error:
PHP Fatal error: Cannot redeclare class Blog in ...
Well, I am not suprised I am getting this error.
What are my options to resolve this?
Prefix controllers in ajax directory with "ajax" (looks only a bit stupid url/ajax/ajax_blog)
Use namespaces (I guess I need to namespace codeigniter too then)
Create 3 seperate phpunit.xml files
This aren't really solutions I am looking for. Do I have any other options? Is it somehow possible to run each testsuite seperatly, but still in one command? Can I "clean" objects between testsuites? Anything else?
There are no other options except those you mentioned, as it is impossible to "unload" class definitions in PHP.
Naming two controllers the same is not a problem when you run CI normally, since only one controller is instantiated per request, but something that should be avoided.
If it is just the ajax-url you don't like, maybe override it in a route (in config/routes.php):
$routes['ajax/blog'] = 'ajax/ajax_blog';

Resources