Sharing controllers, models and views between separate projects in CodeIgniter - php

Kohana, due to cascading file system and modules, allows to share code in common projects, that contains controllers, views and models directories. How can I do it in codeigniter? I want to create sites, that will share some code (admin area views, some models). That is easy in Kohana, we just have to add another directory for Kohana::find_file().

I think this is a duplication of:
Codeigniter Shared Resources - Opinions Wanted
And
How do I load a view from a specific (shared) path in CodeIgniter?

I'm more experienced in Kohana than CI but if I'm right there is a HMVC module in CodeIgniter. You could see if you are able to request a external page like you can with the HMVC of kohana.
If I may ask. why do you use codeigniter when you know kohana does the job better?

Related

Laravel two modules in one project

I started to develop a backoffice in laravel (www.example.com/admin) and take use of MVC structure that is offered.
Now it is needed to develop online store in the same domain (www.example.com). What is the best approach to separate the two modules?
For instance one route file/controller folder for backoffice and other for the front site?
Best
Just like api and web routes are split in two separate files in Laravel 5.3, you could split admin and non-admin routes further in two separate files, passing different Controller prefixes (namespaces) to each one and adding an authentication middleware for admin routes. Look into your RouteServerProvider.php.
That's more than enough for a small-to-medium website IMHO.

Modular Directory Structure With CakePHP

CakePHP is fantastic, it really deserves the slogan "Rapid Development Framework". I have been able to quickly bake controllers, models and also templates. Things were good for a while until I hit a brick wall. The application I'm developing is way too massive for the simple directory structure offered by default.
Half way in my development process, I started to see myself leaving lots of business logic inside of Table classes. I've heard sayings that it's not a good idea to pollute the model class with behavioral code.
Since my application is large that it requires several modules almost mini applications by themselves I need to use CakePHP a little differently. I will explain the structure of my application that I would prefer.
Application Structure (Architecture)
Core
This folder will contain all the modules my application is made of. Alternatively it should be called "Modules" instead of "Core".
Modules
Each module folder will have a folder for Controllers, Models, Services and Templates.
Model
This will contain two sub folders as the ones already offered by CakePHP 3. It will contain the folders for Entities and Tables. I have heard the table acts as a repository so I have omitted the idea of having a repository folder.
Service
The service folder will contain services for the module, mainly business logic code that uses Table Entities for data persistence and retrieval. This is to help keep the business logic centered and keep the model classes & controller thin.
Controllers
Controllers will be the ones talking with the service classes. Using the services to both retrieve data, save data, do validation, work with business logic...etc. My goal is also to also make the work of the controller very light, by moving most of the logic stuff into services.
Template
This will contain the view files that the controllers will use to render data back to the web browser. I might have sub folders in there for views for sub sections of the module.
Notes & Questions
Please forgive me If I have not explained my self properly, we are dealing with a very complex application that has many tables, approximately 100. If anyone has better recommendations for organizing a large application in CakePHP 3 I would really appreciate it.
By developing my application in this way I understand CakePHP will not work out of the box, I might need to reconfigure it so It can uses my custom directory structure. How easy will it be to do that?

CakePHP compared to Joomla

So the past month ive been working alot with CakePHP getting to know the conventions also getting better at the MVC structure and how it works.
Now in cakephp you basicly bake Model views and controllers where Models are assoiciated to Database tables and controllers handle the request back and forward from the Model and the view.
Now Joomla is build in a different way. As far as ive understood Joomla is build up of modules and components but these components and modules follow the MVC structure.
Now to my Question:
How close is cakephp programming to Joomla programming like how does it compare? is creating components and modules the exact same thing as creating Models and Controllers in cake (execpt from the Api calls not being the same)?
The Joomla Framework has its own MVC just like all frameworks. If you develop applications on that it is somewhat different than what you would do building an extension inside the CMS.
Building an extension on the Joomla CMS is different from building an application on the framework and I really would separate that out and figure out what you want. IF you want to build on the CMS because htat give you user management, authentication, cache etc and then you build on top of that, it is a different than than building a stand along application.
So you really need to figure out which it is you want to do.

Module Separation

I'm trying to figure out how I can work with module separation with codeigniter.
Lets say I have a news module where its inside of the application folder and inside the news module folder I have a controllers, models, views folders and files inside of those.
Do I need something additional to do this?
If you want to work with modules in codeigniter you can use Modular Extensions - HMVC which makes codeigniter modular. Here is the link https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/wiki/Home
I hope this helps.

Code reuse in PHP framework between multiple projects

This is my first question here. :)
I am working on a little php framework and started to think of ways to re-use the same code between multiple projects. Right now with this framework it is possible to make multiple application directories for different projects and use the same core - similar of what codeigniter 2 does.
The question about code reuse raised at work when I needed to make a website that is quite different from existing one, but would still use classes from it.
My first two ideas was either use some kind of a global "models" directory where to place files shared between multiple projects (and add option to framework to load them), or to add a possibility to load these "models" from other project(s).
I thought maybe somebody else have some better ideas and wanted to know other developer thoughts on the subject in general.
As an example this could be the current directory structure:
live/ - live site
config/
controllers/
helpers/
models/
public/
views/
admin/ - administration (same structure as "live/")
system/ - framework core
Well I don't think loading models or other classes directly from another project is a good idea. If two or more projects share the same classes, they should be located somewhere outside of both projects. This is the situation where the codeigniter packages comes in handy. It allows to have separate folder for all of your libraries, models etc. and load them in any codeigniter project very easily. Take a look at the official documentation for more details.

Categories