using require in codeigniter - php

I'm trying to use the uaparser.php library to detect the operating system, but when I use the following it just loads the github page for the library. This is the github page https://github.com/tobie/ua-parser/tree/master/php
<?php
require('uaparser.php');
?>
I've placed the file in my includes folder which resides in the Views directory. Perhaps, that is the source of the problem? Where would be an appropriate place to put this file?

I assume when you downloaded uaparser.php you clicked File->Save Page As... (or something simular). That is why the page loads when you require/include it.
Open up the local file uaparser.php and confirm that it is actually the php code and not the html of the page.
Doing this is fine anywhere you need it.
You can place this anywhere, but for codeigniter it should be in the 3rd party folder, but it doesn't matter.

Related

Place Joomla module outside of index.php

I have a php page that is just a page I am linking to, from index.php.
When I try to use jdoc include to place the module, it doesn't work.
Should I do something special to make this php page a part of the Joomla template? Should I make it an article? Or is there just another way to load this module?
You can use this extension https://extensions.joomla.org/extension/jumi/ and on it you can put the path of your php file.

CSS won't work through Heroku when routed through PHP

I am uploading a bootstrap template through Heroku. The name of the template is: Brushed. http://www.alessioatzeni.com/blog/brushed-template/
I route to the home page through a php file with the following code:
<?php include_once("home.html"); ?>
Everything works in the emulator on cloud9, however, when I upload it to Heroku only my HTML shows up without any of my CSS. Does anyone have any idea of what I can do?
Here is a link to my site: https://mariatorres.herokuapp.com/
It is not a rails app, just a static bootstrap template.
If you use Chrome's Code Inspector and go to Network, and try to reload your webpage, you will see that the .css files are 404 not found... you can reproduce the same if you load your webpage, open it's source and see (and try to open) the .css links.. you will see that they are not found. To fix this, where you load the .css files try to use the full path of the CSS, or if you rewrite/route your paths, fix the path to the CSS files..
Only by showing us the include statement, is not enough..

How to use IntelliJ Liveedit with php include

I've been working on a webpage and I wanted to break it out into templates that I could pull in. For example the navbar is common to all of the webpages so it gets pulled in like this.
<?php include("templates/navigationBar.html"); ?>
As soon as I move the code out of the index.php into the templates directory IntelliJ LiveEdit plugin stops updating the main index.php (that's including stuff from the templates directory) when I make changes to one of the templates.
I figure this is because the IntelliJ IDE is "stupid" and will only tell the plugin to refresh the page when it exactly matches the page I'm working on. Is there any way to map those notifications from my templates folder into any php file that might include them?
http://confluence.jetbrains.com/display/WI/LiveEdit
http://plugins.jetbrains.com/plugin/?null&pluginId=7007

php class autoload - seems to be caching?

I've recently implemented the following code to autoload classes in my php code:
function my_autoloader($class) {
include 'classes/class_' . $class . '.php';
}
spl_autoload_register('my_autoloader');
The code is contained in file that gets included at the top of all files that need to generate a web page. So then I set about removing the require_once calls from my code. Here's an example:
require_once('classes/class_web_page.php');
As you'll probably gather from the above, the various pages on my site (it's an online community so there's a forum, gallery, etc) all use the web_page class to generate page headings, menus, etc. The various pieces of code create a web_page object, set various parameters to determine what menu options etc are needed, give the page some content, and generate the html.
All seemed well until I made a change to the class_web_page.php file. The change was immediately apparent on most of the site... except for the home page.
I refreshed my browser, switched if off an on again :-) tried calling http://www.terragenesis.co.uk/index.php rather than just http://www.terragenesis.co.uk/, and even stopped and restarted apache on the server. Despite all this the changes didn't show on the home page. In the end I put the require_once line back into index.php... and presto hey: the changes I'd made in class_web_page.php appeared on the home page.
So it looks to me like the autoloader was loading a cached copy of class_web_page.php and nothing, not even restarting Apache, was going to persuade it to get the new version. Why it should do this for the home page and not the other pages... I have no idea.
Has anybody else experienced this? Have I done something wrong with the autoloader code? How can I fix it... or am I going to have to put all the require_once statements back in place? :-(
My server has PHP version 5.1.6
I found the answer to this... and as usual with "bugs" that elude me for days, it turns out that I did something incredibly stupid:
It turns out that at some point in the past I accidentally uploaded a copy of class_web_page.php into the site home directory rather than the classes subdirectory. So it existed twice.
So, it would appear that despite my autoloader telling php to look in the classes subdirectory, it will look first in the same directory as the main script (index.php in the case of my site's home page). All of the other site page scripts are in subdirectories (forum, gallery, etc) so they were "correctly" using the /classes/class_web_page.php
I've now deleted the copy of class_web_page.php that was living in the home directory... and everything works as it should.
Are you sure that this file is actually loaded (or a cached version of it)?

How to load view from application/myfolder/ path in CodeIgniter

I was loading view in CodeIgniter as
$this->load->view('../../myfolder/footer');
It was working fine on windows machine. I have uploaded app to linux machine and start getting error
Unable to load the requested file: ../../myfolder/header.php
myfolder is in CI application folder.
How can i load view from application/myfolder
Please help me and thank you in advance.
Why you need tho load views in application/myfolder?? Code Igniter expects that views are located in application/views or application/views/myfolder. Put your files in application/views and then you can load it using:
this->load->view('footer');
or
this->load->view('myfolder/footer');
If it worked on Windows but no longer works on Unix, it could be because the filepaths are case sensitive in Unix.
Check the file structure and file names to make sure they match the CodeIgniter requests exactly.
E.g.:
$this->load->view('../../myfolder/footer');
Will fail trying to load:
../../MyFolder/footer
../../myfolder/Footer
../../MyFolder/Footer
etc
$this->load->view(base_url().'myfolder/footer');
That should work but I have no idea why you're trying to work outside the views folder to begin with. Just structure your views folder like below. Load the header, footer and anything else that's static from a template page.
Views
--pages
--admin
--templates
--etc.

Categories