What is preferred code/directory structure for extended modules? - phoenix-framework

What is equivalent of Rails /lib directory in Phoenix? and how code should be structured there?

From What goes in Rails lib/:
The generated Rails README proclaims:
lib — Application specific libraries. Basically, any kind of custom
code that doesn’t belong under controllers, models, or helpers. This
directory is in the load path.
The Rails guide says:
app/ Contains the controllers, models, views, helpers, mailers and
assets for your application.
lib/ Extended modules for your application.
In other words, app/ is
for “configuring Rails”, and lib/ is code that would make sense even
if your application was ported to the console or an Android app for
instance.
The equivalent directory in phoenix would be: your_app/lib/your_app.
and how code should be structured there?
All modules defined in a mix project's /lib directory are available in any other file in your project as ModuleName.func_name(). Phoenix in Action puts the public interface for your app in your_app/lib/your_app.ex with the rest of the files in the directory your_app/lib/your_app/.

Code should be structured like any other Elixir application.
Quote taken from Phoenix Framework docs Adding Page section.
Our lib/hello_web directory contains web-related files – routers, controllers, templates, channels, etc. The rest of our greater Elixir application lives inside lib/hello, and you structure code here like any other Elixir application.

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.

Can Laravel 4 modules be extended by default (in-core-functionality) by other modules like in Drupal?

E.g. in Drupal you have a module called Views and you need that module to run module called Views Slideshow (because it needs to use some methods from Views module controllers/models etc.) and you need these two to run Views Slideshow Extra Effects module (this module use stuff from all two previous and extends that in specific way etc.)
Those names of the modules are just made-up examples, I am not longer using Drupal, but I have very much liked its modules architecture.
So, can L4 offer me this kind of modules environment when I just copy a module with structure like (this structure is used in CodeIgniter's MX HMVC:
modules/
views/
controllers/
views.php
models/
views_model.php
views/
display.php
views_slideshow/
controllers/
views_slideshow.php
models/
views_slideshow_model.php
views/
display.php
views_slideshow_extra_effects/
controllers/
views_slideshow_extra_effects.php
models/
views_slideshow_extra_effects_model.php
views/
display.php
And important question:
Can all this be done without using composer and including my modules in some configuration files etc.?
I dont understand why you do not just use composer? This is exactly what it was designed to do - it will allow you to develop your own libraries/modules and 'plug' them straight into your Laravel 4 app with no changes to the core code etc.
Note - composer modules can be private libraries on your computer - they do not have to be uploaded to packagist.org to be used. I even store my private composer libraries in private github repos that are automatically pulled into my projects.

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

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)

multiple applications with codeigniter from same framework directory?

could i use one codeigniter framework directory to create multiple applications?
cause it seems that i have to have separate codeigniter folder instances for different applications. i want to be able to adjust some code in one place (classes that are universal) and every application i created with codeigniter will be affected.
with yii you could do this.
you can do this folder structure:
system
website-1 (your application)
----application
----index.php
website-2 (your application)
----application
----index.php
website-3 (your application)
----application
----index.php
move the 'codeigniter application folder' from the system and put it in one of you application folders.
copy the index.php file and paste inside your application folder.
In the index.php file:
YOu should have the following:
$system_folder = "../system";
$application_folder = "application";
Both Colin and Thorpe are correct.
Out of the box, sharing is not perfect. If you want to share libraries you have to put them in the system/libraries folder which makes upgrading that little bit more difficult and models cannot be shared at all.
To created a "shared" directory for libraries and models then you can use this MY_Loader.
could i use one codeigniter framework
directory to create multiple
applications?
Yes, you can create multiple applications with one CodeIgniter instance

Resources