Is it possible to access codeigniter functions/helpers from within Magento? - codeigniter

I have a Codeigniter powered site at the root and a Magento powered product catalog inside a catalog folder. I was wondering if it is possible to load Codeigniter inside Magento so I can re-use partials, helpers, etc.
For example: I would like to share the same header in both platforms, so the header.php file in Codeigniter uses the url helper, and functions that Magento doesn't understand
How can I achieve this?
UPDATE:
I've tried the following:
CODEIGNITER
|
\_ CATALOG (Magento)
Inside Magento's index.php file I added:
include('../index.php');
$CI =& get_instance();
echo $CI->load->controller('welcome');
After this, I got an error "Can't find application folder" from Codeigniter when loading site/catalog. So something worked. I cheched this other SO question and inside Codeigniter index.php file I added:
$application_folder = dirname(__FILE__)."/application";
$system_path = dirname(__FILE__)."/system";
The first error was gone but then followed 5 php errors where it could not find CI/UTF8.php, CI/URI.php, CI/Benchmark.php... etc. These are CI core files which are referenced in the bootstap index.php.
This is where I'm stuck...

Have you tried to include your class files to your header templates and call the methods from external lib objects? Or better jet include already outputted header file?

Related

How to bring instance of codeigniter 4 in to my upper directory without affecting its content

If my Codeigniter 4 files are in
www.website/projects/my_cifiles
and my Codeigniter index.php files is located in
www.website/projects/my_cifiles/public
How can I copy an instance of Codeigniter into
www.website/
without Codeigniter affecting the index file in www.website/ ?
Will get_instance() bring the codeigniter class into www.website/ directory?
If you place a file called 'index.php' into www.website/ and in that file you include the following line:
require_once('/projects/my_cifiles/public/index.php');
It will point your browser to the public folder and continue from there.

Why are view files in CodeIgniter saved with .php extension?

From the CodeIgniter docs, I noticed that the view files are saved with .php extension, even if they only contain html. Is there a logical reason behind this?
It is not compulsory to save view files with the only .php extension we can also save them as HTML files, But to load the HTML views we also need to specify the filename with an extension like $this->load->view('my_view.html').
Also, you can check this link for the same discussion view extension in CodeIgniter 3
Q: When we load any class in CodeIgniter like we load the models, libraries in our controllers without specifying its extensions so how CodeIgniter loads the exact file with that name.
A: For this, There are the system functions defined in the CodeIgniter which concat the .php extension with the class name we pass e.g $this->load->library('form_validation')
For Example: How CodeIgniter 3 actually loads liberaries If you can check the system file in system/core/Common.php line no ~141 function
load_class for liberaries
So it will load system/libraries/Form_validation.php file
I hope this will make you clear that why view files in CodeIgniter saved with .php extension.
Codeigniter is a PhP framework, so it assumes the user is (eventually) going to use PhP.
Also, it isn't necessarily bad practice to always use .php instead of .html since .php handles html just fine. Could be viewed as potential future proofing your code.
One advantage of using the .php extension is that a server can be configured to not display the contents of the file. In other words, the lines of text (php code) that are eventually output to the browser (as html) cannot be seen directly. This provides a layer of security by hiding implementation details from the website user.
Because Codeigniter is a PHP MVC (Model-View-Controller) Framework. The view files are .php because they use PHP scripts. That's the idea, but it's not mandatory. You can include pure HTML. The view files are called by "name-of-the-view-without-the-extension".

Codeigniter working directory inside another working directory

Hi I am working on codeigniter for a while now and have met with an issue.
I use "localhost/controller/function" which is how codeigniter works.
Where controller classes are in controller folder in application.
I have a new codeigniter setup in root folder names "big" with its own controller, view, models etc. How can I run files in "big" like I do for my the original application.
I tried "localhost/big/controller/function", which obviously didn't work.
Please help, I am completely new with codeigniter.
just go to index.php of your application (big)
change/add line:
$application_folder = "applications/big";

Opencart header and Footer Call in Codeigniter Site

I have a site in opencart on root and Codeigniter site in sub-directory.
Is there any way to call Opencart Header and Footer in Codeigniter site.
Thanks
Well it is possible to call it, you just have to call the tpl files, but variables used there will throw errors and finally it will not work, only if you had static elements only called in your header.tpl and footer.tpl would this work, in the other cases it will not(you would have to include manyy files, and security issues would come up).

How routing is done in codeigniter?

I could not find the .htaccess file in CodeIgniter framework and i'm wondering how do they do route without it? Or it is somewhere hidden?
There is no .htaccess by default provided with codeigniter. They serve it through the index.php. .htaccess is only used to direct the urls to the index.php. This way codeigniter is working in environments where rewriting isn't allowed. Another way of getting controller and function is by query strings.
Anyway the actual routing is done in system/core/Router.php so you can read the code. Since Codeigniter is open source application that can't be hidden.

Resources