Use CodeIgniter's core functionality only - php

I tried this somehow, but cannot get around the fact of setting the APPPATH. What I want to do is to use CodeIgniter's libraries and core functions, not the whole MVC model but only the helpers built in.
How can I achieve this? I would like to include some .php file into my files as a bootstrap load and get access to all the functionality there is, from database configs to $this->db->... stuff, but not the "load view" and controller stuff.
Any idea on how to approach this?

Related

Creating a Larvel method like view() to import other files

As the title says, I need to create a method in Laravel that works like view('name'), but includes files from another folder.
What's the best way to do this without altering Laravel's core functionality?
I was thinking maybe of extending the functionality but I do not have enough Laravel knowledge to know what's the best place to write the function in and/or the best way.
Created an external .php file that I've included in Laravel's index with the functionality that I need, and it was usable in the .blade.php files as well.

Joomla, is this a bad thing, injecting view, model and controller to container?

As the title says, I just want to ask if this is a bad thing or not if I inject all views, models, controllers and other classes like helpers into the container (IoC) for example like the following image.
Sample:
Note: In this case, I make my own base view, model and controller for my component so I don't use default Joomla instance like JModelLegacy::getInstance(); or JControllerLegacy::getInstance();.
Thanks.
This is what I did. I've tired of constant changes that breaks extensions and force to rewrite them without any actual benefit.
I have forced all MVC classes of Joomla and added my prefix to them. Everything works just fine.
I do not think you will have a problem to load everything at once. At least with the list you've shown. If you would have extension with hundreds of views and models, may be you could be hurt.
On the other hand why would you do that? Decouple your library off Joomla's and it will load everything automatically.

Laravel where to store ajax methods

I'm having a RESTful Resource Controller with basic CRUD functionality. My pages contain a lot of ajax requests, which make a simple controller extend over 500 lines of code, make it very unclear, complex and confusing (especially with working in a team).
How and where should I declare the ajax methods for my controller? I tried messing with php's include_once and put it in a seperated file in a folder named AJAX but this doesn't seem to me to be the right option. What is adviced for this situation?
if you are working on a fairly big project its better to extend it with concepts behind the domain model in domain driven design, such as services and repositories.
you can read more about it in Domain Model
or for simplicity you can put your ajax.js in public folder and call it with asset() laravel built-in function.

CodeIgniter: where should I put custom utils?

I'm using CodeIgniter and I have a few utils that I want each controller (that is, each controller file) to have access to.
The question is: where to put these?
I thought of helpers, but the CI documentation talks only about extending existing helpers, not making your own. I'm sure that doesn't mean I can't make my own helpers, but it does mean I don't know how they should be built (procedural? Methods of the global CI instance? etc)
I also considered hooks, but this is a poor fit I think as I'm not extending core functionality.
Or is there some other way I'm missing?
It's been a while since I've done this but I believe I used two approaches.
Creating a new, custom helper that goes into /application/helpers, following steps noted from this answer: CodeIgniter: Create new helper?
Creating a new library class into /application/libraries which I also activate in the autoload configuration found in /applications/config/autoload.php. This way it's always available to my controllers when I need it. CI has good documentation on this one (http://ellislab.com/codeigniter/user-guide/general/creating_libraries.html).
I did it simply by adding a file to the application/helpers folder (maybe I created that folder - I can't remember) and then loading them in the usual way.

In an MVC Context, Where Do I Put A Class?

straight to the point :
I am using Kohana, and I am looking at another script written in plain PHP. In the script, I have a class ShoppingCart. If I am to convert the script to Kohana, where am I to put the class, its methods and its properties?
Is it in my existing default controller? Or should I put it in a separate controller? Or as noobie as it may sound, will I put it in the model?
That depends on the specifics of the class I suppose. To be honest I don't know anything about Kohana, but there's probably a place for "vendor files" somewhere. Maybe it's best to place it there and write wrapper functions for it in your controller. If the class already integrates well with Kohana you may instead choose to use it as a controller or model directly. Or you might want to take the time to rewrite it to make it work as a controller...
Only you can evaluate the best place for it, there's no hard and fast rule here.
Kohana has a folder for 3rd party libraries. The main one is under system/vendor, you can put it in you application/ as well.
Many PHP class loaders require details like your filename should be the same as the class name (at least that's what I read in the Kohana documentation) if you want the classes to be automatically loaded.
If you need to use 3rd party code in your app it's recommended that you create a folder in your app / module folder called 'vendor' and place all of that code there.
You can then include the files by calling:
include kohana::find_file('vendor', 'filename');
If needs be you can also create a wrapper for the external library, a good example of this is the email helper which uses the 3rd party Swift email library.
If you're porting your own class to kohana then you need to work out what the class will be doing and categorise it accordingly.
If the class will be fetching items from some kind of database then you should make it a model. Libraries are usually sets of code that you want reuse across controllers / models, such as authentication, calendar generation etc. Controllers are used for passing data from models to your views / libraries.
See the docs for more info
As per kohana convention, you should place custom classes in application/libraries folder. However for this, you need to know how to get the class to work after putting it there. If you can't figure that out, you can do anything like putting it in your controller or making another controller of it, etc.

Categories