base controller zend framework 2 - model-view-controller

I wonder if someone here can help, I am just starting with Zend Framework 2 and I am find it slightly daunting to get a project started off properly..
I am trying to create a base controller that I can be extended from. I am currently using the Zend Framework 2 skeleton application.
I have created a Resources folder in vendor/zendframework/zendframework/library. Within the the Resources folder, I have a Controllers folder which houses a BaseController.php file.
How do I get my project to autoload the BaseController in the Resources folder for it to be available through out the entire site?
Any help will be most appreciated.
Thanks

You shouldn't need to create a base controller, ZF2 already provides a number of base controllers for you, such as the RestController and the AbstractActionController
http://framework.zend.com/manual/2.0/en/modules/zend.mvc.controllers.html
If you are going to create a base controller, create you own module and put it in the vendors directory.
You should never need to go into third party modules and modify code as you should be able to inherit and extend the classes that are provided by such libraries

Related

is it important to use the same directories for views and models

is it important to use the same directories for views controllers and models or you can be free to create files inside created folders and refer to them when needed
in Laravel MVC
Check docs Directory Structure
The default Laravel application structure is intended to provide a great starting point for both large and small applications. But you are free to organize your application however you like. Laravel imposes almost no restrictions on where any given class is located - as long as Composer can autoload the class.
I myself haven't tried doing my own folder structure. I would personally stick with the standard created by Laravel and follow that.

How to add custom code to the 'system' folder of CodeIgniter?

I am looking into building my own CMS / extended framework on top of CodeIgniter, and I was wondering how to structure it to keep code out of the application folder. I noticed that in a typical CI set up, the file structure looks like this:
application/ //code for your application
system/ //CodeIgniter core
index.php
However, in PyroCMS, They have used the following structure:
application/ //code for your application
system/
--cms/ //PyroCMS core
--codeigniter/ //CodeIgniter core.
How do I accomplish a similar result?
To emulate that structure just edit the index.php constants:
APPPATH
BASEPATH
#WebweaverD has provide you a good solution to improve your application usgin HMVC. I will give you another.
How about something like this:
-system/ //CI core
-index.php //manage the front_end requests
-acp.php //manage the back_end requests
-apps/ //applications dir
--back_end/ //only "admin" controllers, libraries, config. No views here
--frond_end/ //only "user" controllers, libraries, config. No views here
--acp/ //views for back_end
--themes/ //views for front_end
All above can be implemented as you want only extending the necessary core files.
The short answer is that everything starts from index.php, this is where core/CodeIgniter.php is included and it is also where application and system paths are set (retrieving values from config).
I think that pyro cms actually sets /system/cms as the application folder, presumably they have written code which looks at the presented application folder for content and processes it.
Another approach is to use wiredesigns modular HMVC:
https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc
This will allow you to separate your code out into modules. Just have a folder called cms containing all your cms modules and another folder to build your custom content on top.
You set the path to your modules folder in the config so if you wanted your cms code in the system folder you could set the path to your modules folder there and build on top using codeigniter in the standard way, perhaps adding a hook before or after your controller is loaded to call the cms core.
Mine is just a suggestion but you can easy fork pyrocms and build your own cms on it.
PyroCMS will deprecate codeigniter in the next version so you can keep their code and fix it where you need and modify it as you want

Overriding Joomla core component file

I am trying to override the com_content/views/article/view.html.php file in joomla using the instructions given in this page
It says I have to create a folder named 'code' in base directory and create the same directory structure. I tried it , but its not working. Can someone confirm whether its working.
Where should I create code folder? Is it on root of joomla installations?
PS- The edit is working correctly when applied on core file
You can override (nearly) any class in Joomla, if your class with the same name is loaded first. To ensure that, you need to create a system plugin.
Here is an example for root/components/com_content/views/article/view.html.php:
class plgSystemOverride extends JPlugin
{
public function onAfterRoute()
{
JLoader::register('ContentViewArticle', 'path/to/override.php', true);
}
}
CAVEAT: Overriding a core class can lead to problems with other extensions, if you're not very careful. For views, though, any interferrence with other extensions is less likely.
You can't override component controllers, models and views in core Joomla! without using a 3rd party plugin.
The plugin you need can be found here: http://extensions.joomla.org/extensions/style-a-design/templating/15611
The code folder then goes into your Joomla root unless you're overriding a back-end view in which case it goes into /administrator
Hope this helps :)
You can use the Class Overrider Plugin http://extensions.joomla.org/extensions/tools/development-tools/23994
just adding some simple human reading commands

How to load a library from Module using codeigniter modular extensions

i need to load a library from my module using Modular Extensions
my structure like this
modules/
modules/categories/library
categories_class.php
modules/categories/controllers/
categories.php
I need to load categories library in categories controller .
any one cane help me?
I see two problems..
Problem 1
According to your question, your categories module is not organized properly. The whole purpose of HMVC is compartmentalizing of code e.x; modules. Given your present question how does that structure allow you to copy your modules folder and paste it into another app? Answer: It doesnt..
Follow the example below
It should be the following from the app root:
/application/
config
modules/
categories/
views
controllers/
categories.php
libraries/
categories_class.php
models
libraries
core
controllers
Problem 2
per the user guide: https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/wiki/Home
You must prefix the module name in front of anything referenced inside the modules folder.
e.g: $this->load->library('module/library');
or in your case: $this->load->library('categories/categories_class');
I have attempted previously to exclude the modules folder name and have never gotten it to work.
Controllers can be loaded as class variables of other controllers
using $this->load->module(’module/controller’); or simply
$this->load->module(’module’); if the controller name matches the
module name.
Any loaded module controller can then be used like a library, ie:
$this->controller->method(), but it has access to its own models and
libraries independently from the caller.
I have another perspective for this error behavior, that make me spend about 3 hours, actually I am always using combination of Uppercase and Lowercase on my custom libraries on Codeigniter.
For wiredesigz of Codeigniter HMVC, remember the libraries loader behavior as same as CI itself, always use lowercase of your library classes name instead of actual class name (Maybe combination of uppercase and lowercase)

Zend multiple directories and MVC routing

I'm building my first personal website using Zend 1.11. To create the directory structure I've used the zf script that comes with the framework. I can use the same script to create controllers/views like so:
/home
/contact
/blog
/about
Yet where I've come unstuck is trying to encompass multiple directories e.g.
/contact/address
/about/cv/workhistory
...I just get an error saying the content cannot be found. There is no model, just a controller (route?) and a view. I've tried adding the desired directory structure when I use zf but this results in an error e.g.
zf create controller about/cv/workhistory
Is this even possible in MVC or does it show a lack of understanding of what MVC is on my part? Thanks in advance for any help/tips/pointers
ok you've created some controllers. Now it looks as though you want to add some functions to your controllers.
In order to do /contact/address it would be appropriate to have the addressAction() inside your ContactController().
A controller is a group of actions (read METHODS). When you built your application 2 controllers were built with it, one of them was the IndexController() that also gave you your first action indexAction() and your first view index.phtml located at /application/views/scripts/index:
<?php
class IndexController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
}
}
Zend Framework implements the MVC paradigm with actual Models, Views and Controllers. In the controllers are your actions grab data and prepare it to be viewed.
Go ahead and do yourself a favor and run through some tutorials, here are some suggestions.
Rob Allens ZF 1.11 tutorial
Zend Framework Quickstart
The naming conventions are important to understand and can be found at:
Zend Framework Naming conventions

Resources