I'm trying to install CodeIgniter (I have Mac). I have no experience with Frameworks, but I've read a little about MVC. My goal is to get CodeIgnitor set up so I can use it.
so I download CodeIgniter, then in one tutorial I'm told the following: Copy the file to your server’s web root folder, usually /var/www/ !
In this tutorial: http://www.phpeveryday.com/articles/CodeIgniter-Introduction-to-CodeIgniter-Framework-P147.html
I am told to "Open your root web server" and put the folder inside.
What is the "root web server"? Is it my htdocs? Where am I supposed to put this folder?
I put the folder into my HTDOCS folder because thats where all PHP files go, but I'm not sure if I did it right.
Please, install the easiest thing in the world XAMPP
find folder xampp/htdocs (desired web root folder) and create folder in it (project name), unzip/unrar/un7z CI in there so your folder structure is going to be
xampp/htdocs/project_name/application
/system
/index.php
Open up project_name/application/config and go thru all files see them one by one so you know what CI can and can not do it is well explained inside each file what every setting does.
If you are new to CI follow this video tutorial
if you are looking for good .htaccess file grab this one and change for whatever you need
note: this file should be in /project_name
note2: also in config/config.php set index_page to $config['index_page'] = '';
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /<your project name>
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
after changing .htaccess and config/config.php your urls are "nice"
localhost/project_name/controller/method/parameter1/parameter2
finally: it is CodeIgniter not CodeIgnitor
Related
I used CodeIgniter for most of my projects a while back. I'm getting back into the swing of things and hitting some bumps. I'm now developing on Mac OSX Mavericks and using MAMP as my Apache server. Everything seems to be running okay but I can't get rid of the index.php in the URL the whole time. I have added in the .htaccess file into the root of the project. Here's the file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ez-recruits/
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
I'm not super clued up about how to make these files so generally I just get them from CodeIgniters website. I'm getting a 404 Error without the index.php in the URL and if I manually type it in, the page will load fine. Also, I was developing in Firefox and I was getting an error saying "Firefox could not understand the address" without the index.php in the URL. I do have mod_rewrite activated on the Apache server. I have removed index.php in my config file for the index page and I have set the base_url to
$config['base_url'] = 'localhost:8888/ez-recruits';
I did some research and found that changing the httpd.conf file helped someone else, so I changed the part of it to this:
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
</Directory>
But it has changed nothing. Does anybody know what I could be doing wrong or if this is just a Mac problem? Also, with all of these configurations, will I struggle to develop alongside someone else who is developing on a Windows machine?
Thanks in advance.
Try this for your .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
#RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
Also, you can leave $config['base_url'] blank, which makes life easier if you're working on multiple systems.
Hope this helps!
You need to use base_url and index_page in the config.php file
$config['base_url'] = 'http://yourlocalurl/';
$config['index_page'] = 'index.php';
Ensure the following helpers are loaded in config/autoload.php
$autoload['helper'] = array('url','file');
I started working on CodeIgniter recently and I'm having some issues with the .htaccess and the base_url() function causing issues. I hope this is just a noob error and has a quick fix!
Pretty much what happens is that now with the .htaccess the index.php is gone from the url which is amazing but now I am having issues linking stylesheets and js files with my templates.
In all the tutorials I have read/watched, they have included the .htaccess and then still set their base_url() and then using "link_tag(href);" to link their .css but now I am getting a double up on the url. For instance when I tried to add the stylesheet, the path that it looked for was:
http://www.mysite.com/site/www.mysite.com/site/css/stylesheet.css
So my first thought was just to remove my base_url() so that the .htaccess does everything but it doesn't work. With the .htaccess I can have a site without the index.php being there but without stylesheets or JavaScript files linked or I can have a site with some styling, but deal with the index.php. There must be a way that both will work simultaneously?
Also, I did a fix by instead of using the link_tag() I just echoed out a normal link tag which works perfectly in the beginning when its still:
http://www.mysite.com/
But if the login is incorrect and I redirect to load the login view again, the styling disappears because its now using the relative path from:
http://www.mysite.com/user/login
Thanks in advance! Any help would be appreciated.
Try
RewriteEngine on
RewriteCond $1 !^(css|js)
RewriteRule ^(.*)$ /index.php/$1 [L]
So www.mysite.com/css/mycss.css is retrieved normally where as www.mysite.com/something is passed to codeigniter.
To get the css file with base_url() you would do base_url("css/mycss.css"), which should result in "http://www.mysite.com/css/mycss.css"
A better .htaccess ruleset would be:
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
This disallows access to your system and applications folder, but allows access to all other files, for example: /js/*, /css/*, /img/*, etc.
I'm building my website in codeigniter, and here an example of a routing rule that's giving me some trouble:
$route['updategamepage/(:num)'] = 'maincontroller/main/updategamepage/$1';
So is there anything wrong with the format/structure of the rule? Here is an example url that uses that rule:
http://www.mydomain.com/ci_website/updategamepage/6
and when that page gets loaded, the css/js don't get loaded with the page...any idea on whats going wrong?
Your routing rule should only apply to things that get routed through CodeIgniter's index.php file. That routing is dictated by the application's .htaccess file. It's possible that your htaccess is redirecting requests to your .css file to CodeIgniter when you don't want it to.
Ultimately you may way to check your web server logs, including potentially enabling mod_rewrite logging, to see what's actually going on.
Here is an example .htaccess that I use for my CodeIgniter apps:
(Notice you will have to change the RewriteBase directive near the top)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /app/
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
Here's a short .htaccess snippet I always use in my projects, it's much easier to understand.
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|shared|uploads|robots\.txt)
RewriteRule ^(.*)$ /index.php?/$1 [L]
what it does is that it redirects every url that doesn't contain index.php, assets, shared, uploads and robots.txt right after the URL to your public folder to your index.php file allowing you to set your $config['index_page'] value to '', that will make your URL's much more pleasant for the eye and search engines. Without this you had URL's like http://www.mysite.com/index.php/pages/about, with it you will have http://www.mysite.com/pages/about.
Personally I keep my JS and CSS files in assets folder, but if you like to keep them in the root folder, simply add their folder names to the second line of the .htaccess file I provided separated with a | sign
RewriteCond $1 !^(index\.php|js|css|shared|uploads|robots\.txt)
As I suggested in my answer to your other question a few minutes ago, you better erase the contents of your $config['base_url'] value and let CodeIgniter do the job for you - he does it really well.
I added the following to my CodeIgniter project to my .htaccess in order to remove the index.php:
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
Everything worked fine. My URLs no longer need index.php in the.
However, this has created an interesting side effect such that when I try to login using Facebook OAuth, I get the following error:
The webpage at
=">https://www.facebook.com/dialog/oauth?client_id=123&redirect_uri=http%3A%2F%2Fwww.domain.com%2Fsign_in%2Ffacebook%2F&state=8f3d1e5de60e47935460564a41f35af3&scope=email#=
has resulted in too many redirects. Clearing your cookies for this
site or allowing third-party cookies may fix the problem. If not, it
is possibly a server configuration issue and not a problem with your
computer.
NOTE: client id and redirect URI have been changed for privacy.
I'm using the PHP SDK 3.1.1 https://github.com/facebook/php-sdk and followed the sample code on http://developers.facebook.com/blog/post/503/. When I still had index.php in my URLs, everything worked fine. The problem seem to have started after I added the the rewrite rules to remove index.php.
Any ideas what's going on and how to fix this?
Try to following patch:
In system/core/config.php file, in site_url method replace the following line
return $this->slash_item('base_url').$this->slash_item('index_page').$this->_uri_string($uri).$suffix;
with new code:
return $this->slash_item('base_url').$this->_uri_string($uri).$suffix;
It might get working...
I want to create a website where the main pages will be served from CodeIgniter. I will use Wordpress in the /blog/ sub-directory to host the blog. Thats it! I want nothing else. Just to make sure that:
example.com/somepage/ calls a CI controller where as example.com/blog/some-post/ is handled by Wordpress.
I don't need any kind of integration or interaction between CI and WP.
Is it possible to install in that way? If not, any workarounds so that I can achieve the objectives?
Thanks and Regards,
Masnun
I suspect you could get this to work using an .htaccess file in the root directory of your site. If blog is the name of the subdirectory where WordPress is installed, and you want example.com/blog to be handled by WordPress, try this to see if it helps:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt|blog)
RewriteRule ^(.*)$ /index.php/$1 [L]
+1 with Rich's method
Additionnaly, if you're using a .htaccess file like the one suggested on CI doc, it should work by dropping WP directory directly into web root dir.
RewriteEngine On
RewriteBase /
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#This last condition enables access to the images and css folders, and the robots.txt file
#Submitted by Michael Radlmaier (mradlmaier)
RewriteCond $1 !^(index\.php|robots\.txt|corporate|assets)
RewriteRule ^(.*)$ index.php/$1 [L]
Because of the RewriteCond %{REQUEST_FILENAME} !-f and RewriteCond %{REQUEST_FILENAME} !-d any call made directly to a real file on webserver would be served directly by Apache, other uris wil be handled by CI's routing mecanism.
Notice we used a last RewriteCond directive to exclude calls to certains files, including our assets dir (containing images/css/js static files) and 'corporate' dir which contains in this case a blog.
Although this example do not use wordpress, it has its own url-rewriting and routing system.
In a matter of conclusion, you'll have use a specific RewriteCond statement if you want to use WP url-rewriting, if not it could work without it.
It should work just as you described it without any complicated configuration. Just install codeigniter in your root directory and then create a blog directory and put wordpress in there.