I've a little problem.
In a controller i will load a function wich is in otherController.
I just use
$pCtrl = new otherController;
for loading the class in that otherController.
The problem is that at that moment the otherController has not already been loaded. So the class is not available.
Can i find a way to tell codeigniter to load all controllers (folder controller) before doing other thing ?
Thanks for help.
This is bad practice. You should be using a CodeIgniter Library to do this instead.
Though, if you're already doing bad things, you could just open the /controllers directory in your config/autoload.php and configure codeigniter to autoload all available controllers. Not sure if this will work well (and efficiently) in practice, so try using libraries.
Its better to create a helper function or a library ..
oh btw , you can use HMVC also .
Related
I am not able to make Codeigniter v3.1.8 work with Medoo DB framework. Is there any instructions how to do that? Should i just include Medoo lib or preconfigure Codeigniter settings?
As the Medoo php file is namespaced, uses use statements, and contains another class Raw you cannot load it as a library (at least not until CI4 rolls out). It would probably be the easiest to just require the file as necessary or to use composer to autoload it (which CI supports).
Otherwise you could just create a MY_Controller in application/core and require it at the top of the file e.g.:
require(APPPATH . 'third_party/Medoo.php');
class MY_Controller extends CI_Controller {
}
and then any controllers that need it should extend MY_Controller.
Alternatively, you can follow my answer here (technique to load namespaced libraries): How do I include the OOP "defiant randomdotorg" library in codeigniter?
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
I want to include an external configuration file in a Magento Observer Model
My observer is in magento/app/code/local/Mycompany/Mymodulue/Model/Observer.php and i want to put my code in magento/scripts/examplename.php
I don't want to use a helper because this code will also be used in other scripts paced in that folder and code repetition is not a good practice
Which is the best way to do this?
Magento is a php application and you can use include() and require() everywhere in your code however this is a bad idea to place classes and spaghetti code inclusions in random places on your server as Magento already includes lib folder and autoloader for those if you follow the naming conventions.
The way I found to do what i was looking for is:
require_once BP.DS.'scripts'.DS.'examplename.php';
where BP and DS are Magento constants, BP=Base Path and DS= Directory Separator
Im building my first application using CodeIgniter, i need a bit of advice.
There are 2 functions that do the same thing and i was wondering which is the best to use.
Ok, so usually when im building a site, i link to the homepage by a simple / but if building on a directory, it will take back to the root public_html directory, with codeigniter i have found both
site_url()
and
base_url()
but, they both seem to do the same thing .. Just wondering if theres any difference, which one is better to use, etc etc.
Cheers,
If you are using index.php
site_url()
will include the index.php , and
base_url()
will not include it.
If you are creating a url to pass, use
site_url('images/img.png')
otherwise...
base_url().'images/img.png'
I am using Codeigniter with the HMVC Modular extension and have a backend CMS area for managing website content. I am routing the base URL + "admin" (http://localhost/cms/admin) to controller methods with the prefix "admin_".
e.g. function admin_index() {...}
And here is my routing:
$route['admin/([a-zA-Z]+)/(:any)'] = "$1/admin_$2";
$route['^admin/(:any)(/)?'] = "$1/admin_index";
$route['^admin(/)?'] = "dashboard/admin_index";
$route['admin/logout'] = "login/admin_logout";
With the HMVC it is not routing correctly now. Here is what happens:
URL: http://localhost/cms/admin/faqs
Directory: modules/faqs/controllers/faqs - index method
--
here is where it breaks
--
URL: http://localhost/cms/admin/faqs/categories
Directory: modules/faqs/controllers/faqs - categories method (does not exits)
Desired: modules/faqs/controllers/categories - index method
How can I use HMVC while maintaining the "admin" are of the website?
You are making life a bit too tricky by putting frontend and backend functions in the same controllers. Have a look at my article on how to create an admin structure in CodeIgniter.
I'm working on something similar, and implemented a swapping like you did (3rd option) and it worked fine.
I tried to implement a front controller to handle the admin section, and run modules with HMVC modules::run() and buffer the output as I wish, but then I have faced another issue, you will have to change the URI schemes from / to _ or something else, since you wont be able to send module segments as parameter to your controller because CI relies on "/" for it's routing mechanism.
The only way is to emulate the admin section as Phil suggested, but there is another option to still have control over the code implemented by anyone using your CMS.
You could extend CI_Controller (or MX_Controller in case you are using HMVC) and add an Admin_Controller which will handle your logic and control what modules can do.
Have a look at this CodeIgniter Base Classes: Keeping it DRY