Integrating Zend Controller Standalone - without the rest of Zend Framework - php

I am using specific parts of the Zend Framework in my application, and I would like to replace my home grown controller with a Zend Framework controller.
My home grown controller is based on an index.php file to which all requests are submitted. A controller is instantiated based on parameters sent within the request
After processing the user is forwarded to url which is based on the request information, either a url is specified or some data is analysed
I would like ideas on how to integrate the Zend Controller within my application
Thanks in advance
Update: I am willing to import the rest of the dependencies, infact I already have Config, Exception, Registry, URI and View. However, I do not want to change my layout to the Zend Application layout. It seems that I may need to use the FrontController but I cannot seem to find any examples

By default, if you generate a default Zend Framework project, it won't have any layout. If it does, just comment or remove resources.layout.* in your config.ini or in the Bootstrap.php
Zend_Layout is part of the Composite View Pattern which basically means it acts as a wrapper for the other views.
You should be fine by running a default Zend Framework application and remove the layout to only use the view.
Note, that you can still use a layout with only <?= $this->layout()->content; ?>

Related

Prevent Apigility from conflicting with routes from existing Zend Framework 2 projects

I have an existing Zend Framework 2 project. Now I've been experimenting and considering rebuilding the front end to be entirely AngularJS, as opposed to the now with Zend Framework 2 MvC coupled layouts and views. But for that reason, the models and controller with their respective routes exist and they use services that have a lot of business logic.
If I were to add an API to this existing project through Apigility, say, for external third parties to be able to access account information, how am I supposed to do that without interfering with my current controller routes?
Apigility Admin UI automaticly creates routes appending the base url (www.domain.com/[api url]). This does not directly conflict when I have an AccountController with /account routes and an API route that uses /accounts/[:accountId] but mistakes are bound to happen.
I should use a url like api.domain.com, however Apigility Admin UI adds the routes automaticly and has, as far as I have seen, no option to create a subdomain route through subdomain 'api'. Of course I could modify the automaticly generated routes every time I make changes through Admin UI but that seems like a hassle and prone to error.
While spreading my question around for an answer, someone on the #apigility IRC channel was friendly enough to give me an answer.
I was overthinking this, as dualmon mentioned in the comments. I had thought Apigilty Admin UI was a tool for managing the whole API. nuxwin^ on IRC told me that while Apigility Admin UI does automate routes for you which can be configured with a base url, it's still only meant for development time. It would mean if I were to route my subdomain to a module I could do that after developing the API.
Simple solution, I just had been overthinking that tool demanded me to follow a certain path.

Is there a global REQUEST handler for CodeIgniter or at least PHP like in Global.asax on ASP.NET?

In ASP.NET I have the Application_AcquireRequestState method in global.asax so that I can handle all requests that hit my application, so then I can do some things like take care of cookies or URL segments or anything I want before execution of the controller code itself
Is there anything like that in PHP or in CI specially?
It sounds like you're looking for CodeIgniter Hooks - check out the pre_system and pre_controller action hooks in CodeIgniter. You could also opt to extend core system classes if you're feeling particularly daring.
CodeIgniter is just a model-view-controller framework with a front controller, so you could always just modify index.php in the project root prior to when the CodeIgniter Bootstrap gets loaded. All application processes route through index.php (the front controller).

How to set up a backend and frontend application in zend framework 1?

I have the following zend framework application
What is different is that I added another application tree inside a backend folder.
What i am trying to figure out is how to make the backend application aware of the main application classes.
For example, in the bootstrap.php from the main application tree I have a call to a method: Application_Model_ModuleLoader::load()
If I do the same inside the second bootstrap from the backend tree, it will error out Class 'Application_Model_ModuleLoader' not found ..
Any ideas?
Use Backend as module, Frontend is the same.
See my example below:

Internal forward action in CodeIgniter

In Zend Framework, we can easily forward to an action in another controller using the _forward().
How to simulate this in CI? CI only have redirect but this is not I want, I don't want user to see the URL has changed in their browser.
Any idea to implement it?
I know for a fact that you can forward to another action inside the same controller without changing the url., with
$this->action();
Other than that, I do not see a built in way to access other controllers
This concept actually seems to break a more strict view of the MVC model, and this functionality you are trying to implement might be better suited for a library.
This sounds like HMVC (Hierarchical MHV) - i.e. controllers being able to load controllers without having to go through the HTTP interface again. You can install a package called Modular Extensions (by wiredesignz). Get the very latest from bitbucket, https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/overview.
Note that support for codeigniter V1.7 has been recently discontinued, so you'll need to user CI V2.0

Is .zfproject.xml a must in a Zend Framework project?

Is .zfproject.xml a must in a Zend Framework project?
What does it do?
Is it's location absolute?
When using Zend_Tool to manage your Zend Framework project, .zfproject.xml will contain your application structure state. This is required by Zend_Tool (and only by it) to be able to work, e.g. add code to certain parts., generate things, etc.
Quoting ZF Manual on Zend_Tool_Project:
So, for example, if in one command you created a controller, and in the next command you wish to create an action within that controller, Zend_Tool_Project is gonna have to know about the controller file you created so that you can (in the next action), be able to append that action to it.
I am not sure if Zend_Tool can be configured to use a different path to .zfproject.xml. My suggestion would be to leave it untouched. It's a hidden file anyway.
Just to add, the zfproject.xml is not needed if you don't use Zend_Tool.
So it's not a must. Personally, I manage all my zf projects more or less without a command line and it works fine for me.
Basically if your going to use Zend_Tool, stick with it. Zend Tool doesn't like it when you create MVC manually. Its just another layer of abstraction that you can probably live without.
I am using zend framework 1.10. Whenever I create a action using zf tool it re-indents the code in the controller file and removes some function closing brackets. It is kind of buggy, so will not be using it from now on.

Categories