I am trying to implement a OrientDB HTTP connection in Code Igniter, but I can't quite decide how to go about it. Basically, I am using the php code found here, and I cannot decide whether to make that file collection into a library or a helper.
Right now, I am leaning towards a helper, because $this->load->library() automatically instantiates the class, where I will need the ability to call static methods as well (as can be seen in the use of BindingParameters::create('http://admin:admin#127.0.0.1:2480/demo');) in the example code.
So, if I make these files into helpers, which should not instantiate the classes, is there a way to load them without adding a "_helper" suffix to the files themselves? I would like to avoid using require/include, but if there is no other way to accomplish this then I have no choice.
Does anyone have any tips or ideas that may help me with this? Thanks beforehand.
Related
I feel like I need to change a couple methods in style.js in order to integrate it into my app. What is a "best practice" for adding methods or even overriding methods in core objects? I plan on doing upgrades in the future, so I don't want to edit the style.js file itself.
The way to extend CKEditor is to create plugins for it.
If you have to modify something inside a closure then a plugin won't work for you and you'll have to get the source code and modify it and from then on keep using that patch.
I Searched a lot to find the answer to this question, here on stackoverflow and over on google. But was not able to find anything...
So, my question is: It is a good practice to extend a controller (in my case BaseUserController from zfcuser) once in a module, and once more in another module?
Thanks for all your replies!
It's fine, I would not go as far as "good practice".
Excessive use of inheritance can cause you issues in any language and there are numerous of post around explaining the issues and possible solutions.
From a ZF2 perspective in doing so you will have the issue where Module B depends on Module A which may be a problem - However this really depends your application/module design.
There are other alternatives:
Aggregation -
create new functionality by taking other classes and combining them into a new class. Attach an common interface to this new class for interoperability with other code.
Use PHP traits - If you lucky enough to use the more recent versions of (PHP 5.4+) the you can simply reuse these within each controller class that requires it.
A Custom Controller Plugin - ZF2 has a "pluggable" API within the controller, meaning you can write self contained helper classes that can then be used in any controller - No need to extend. You are almost certainly using these already with $this->redirect() or $this->params() so they might be good places to start to see how they are built.
I believe Smarty templates has functionality built in that allows you to manage your site URLs from a config file so if something gets moved, you only have to update the URL in one place. Does this sort of functionality exist in CodeIgniter? If not, any pointers or examples on how/where to add it?
For example:
Instead of hard-coding the link it would be: Settings
But where would you want to set $links so that it was available everywhere? Or is it really best to just hard code them?
Take a look at the config class. It allows you to make custom config files.
It's not entirely made for URL's but you sure can use them.
The base url should be basically right at the start of /app/config/config.php, where app is the name of your codeigniter application folder. You access it through calls to the base_url() function.
Yes, it's called Routes, configuration located at config/routes.php. Documentation
If you ask about the rendered html of the links, then your best bet would be using site_url() in conjunction with constants, for example site_url(URL_SETTINGS);, there is no built in functionality for that, but I can say I don't think that is necessary as it would be used too rarely, but it would influence performance every single load.
I'm moving an app from flat file php to codeigniter and I'd like to integrate the two as much as possible before moving over completely. I'm looking to specifically use the input class outside of codeigniter but it looks like I'd also need to use the controller logic (to get access to input segments). Can anyone walk me through using the input library in a flat file php?
I think you're creating too much work and potential problems by trying to do this. You'll be better off if you go directly to CI. Move any standalone functions in your standard PHP files into Helper functions.
If you really want to do this, you could use CI and create controllers/functions for all your files, then in the controller functions, just include() your PHP file and ignore the models and view for now. That way you'll have access to all the CI variables, including the $this->input data.
I've started a CI project and I'm going to use it with Doctrine, there is benchmarking system for the latter and I'd like to remove the ability to use native CodeIgniter DB class, since it won't be benchmarked. I though about simply removing the corresponding files, but I'm afraid it could cause CI errors in other places. How can I remove the ability to use native CI DB class?
I personally would not do it. I just want to force the future developers with random level of qualification not to load it as well
I also use Doctrine in connection with CodeIgniter and there is no need to do anything with the CI DB class. Just ignore it and use Doctrine as you would do normally. If you don't use the DB classes or don't load it, they won't get benchmarked.
If you haven't already found it, look at the wiki, ot gives a good idea what to do with Doctrine
edit to your 1st comment: If you really want to disable the DB class, I see one way: either delete the core file(s)/folder(s) or rename it so that a loading just fails. Alternatively, change their code so they cannot be loaded. If you do so, it should be really well documented somewhere so that the error will be obvious to someone after you.
Don't load it in your controller.
Theoretically, you could create a hook and disable CI's DB functionality. In the hook, you would extend the CI_DB class and the display an error message if the class gets loaded. I'm sorry I can't give specifics, but you'd probably have to inspect the system's database classes to see what would need to be altered.
At least that way, you wouldn't need to make changes to the CI core.