CodeIgniter form_open not hitting controller - codeigniter

Hi all I am new to CodeIgniter framework. I tried to develop a page which contains a form.
Here is the view
<?php echo form_open('Site/check');?>
User Name: <?php echo form_input(array('id'=>'Username' ,'name'=>'username' ,'class="input-medium " ')); ?>
Add User:<?php echo form_submit('submit','Add User','class="btn btn-primary"');?>
<?php echo form_close();?>
This is the controller
<?php class Site extends CI_Controller{
function login() {
$data['records']="BHOOM!!!";
$this->load->view('login',$data);
}
function check() {
$this->load->view('showmessage');
}
}
?>
The showmessage is a PHP page with a hello in <h1> tags.
I already googled and searched for similar issues, but I didn't get any resolution
The base url is localhost/ci/index.php
Error
Unable to load the requested file: showmessage.php
.htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|js|css|img\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]

Here is a tutorial straight from EllisLab. Follow steps and you will get your form working.
The most common mistakes,
not loading form helper
htaccess. is set wrong, or paths are wrong (capital letters etc.).
config.php is not set properly
not passing data to view ($this->load->view('some_view', $data);
Hence you did not provide us error message if one exists there is no possible help from the community.
For more debug info please turn on codeigniters profiler ($this->output->enable_profiler(TRUE);), use PHPs native function var_dump($variable);.
Make sure error reporting is set to E_ALL in your index.php
edit
Make sure your /config/config.php
/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = "";
make your .htaccess this file should be located in root of your project eg. /ci/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ci/
# Reenable after getting ssl cert
# RewriteCond %{HTTPS} off
# RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
# Removes access to the system folder by users
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
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.
ErrorDocument 404 /index.php
</IfModule>

just use this type of code for your trial
view
<?php
echo form_open('controllet_name/method_name');
form_input(array('id'=>'Username' ,'name'=>'username' ,'class="input-medium " '));
form_close();
?>
controller
()
{
$name=$this->input->post('username');
echo $name ;
}

I think your RewriteRule is wrong.
Try:
RewriteRule ^(.*)$ /ci/index.php/$1 [L]

Related

CodeIgniter application links not working

I installed an application built with CodeIgniter on my local computer which has MAMP. The home page contains a bunch of links to other pages. Clicking any of the links doesn't do anything. The page just refreshes but the browser doesn't redirect. Looking at this piece of ducumentation, I think that the URI doesn't have any data and therefore it just goes back to the home page. What do I need to do to test this and fix it?
There are three reserved routes:
|
| $route['default_controller'] = 'welcome';
|
| This route indicates which controller class should be loaded if the
| URI contains no data. In the above example, the "welcome" class
| would be loaded.
change your .htaccess to Codeingiter's provide htaccess file below.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
place that to your root application folder.
Set the base_url of your application in config.php to the same url you are using to access the website, it should be something like this:
$config['base_url'] = "http://localhost/your_app_directory_name";
It should work.
For .htaccess use this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Unable to route to static PHP page in CodeIgniter

I'm a newbie to CodeIgniter. In my 'views' folder, I've created 2 PHP pages - home.php and register.php. I've also created the header and footer PHP pages in a templates folder.
Here is my pages.php code which is the controller class:
<?php
class Pages extends CI_Controller
{
public function view($page)
{
if(!file_exists(APPPATH.'/views/pages/'.$page.'.php'))
{
show_404();
}
$data['title'] = ucfirst($page);
$this->load->view('templates/header', $data);
$this->load->view('pages/'.$page, $data);
$this->load->view('templates/footer', $data);
}
}
and here is my routes.php code:
$route['register'] = "pages/view/register";
$route['default_controller'] = 'pages/view/home';
I have not yet written anything into the .htaccess file.
My project home directory is 'ED'
I am able to navigate to the home page with this URL: http://localhost/ED
However I'm unable to navigate to the registration page with these URLs:
localhost/ED/register
or
localhost/ED/register.php
Please help as to how can I achieve this.
You have to have the index.php by default because according to CodeIgniter URLs
By default, the index.php file will be included in your URLs:
example.com/index.php/news/article/my_article
So if you want to remove the index.php, you can follow this simple step:
You can easily remove this file by using a .htaccess file with some
simple rules. Here is an example of such a file, using the "negative"
method in which everything is redirected except the specified items:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
In the above example, any HTTP
request other than those for index.php, images, and robots.txt is
treated as a request for your index.php file.
Just put your .htaccess file(with the mod rewrite) in you main appplication folder and voila it's done.
What I did with my .htaccess was this one:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /name_of_your_codeigniter_folder/
#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>

my route in codeigniter does not work for dynamic pages

my page url is
http://example.com/ci/pages/portofolio
My roots in config/routes.php
$route['default_controller'] = "index";
$route['pages/(:any)'] = 'display/display_pages/$1';
$route['404_override'] = '';
My controller in controllers/display.php
class display extends MY_Controller{
function __construct(){
parent::__construct();
}
public function display_pages($seo_name){
echo $seo_name;
}
}
i receive this message
Not Found
The requested URL /ci/pages/portofolio was not found on this server.
Try removing $1 at the end of your route. Make it look like this :
$route['pages/(:any)'] = 'display/display_pages';
Your route.php is correct. The way you are printing the $seo_name is not.
public function display_pages(){
echo $this->uri->segment(3); // it will print $1
}
Check http://ellislab.com/codeigniter/user-guide/libraries/uri.html
The htaccess should be something like
<IfModule mod_rewrite.c>
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]
#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>

Configuring Codeigniter with Tank Auth

Something in my CI configuration is missing a "/" that Tank auth view files are expecting and I can't figure it out. I hope you can!
Here are some details:
$config['base_url'] = 'http://localhost/CI/';
I do not have .htaccess set up (so I still have index.php in my URI)
When Tank auth loads one of its view files, here is the first line:
<?php echo form_open($this->uri->uri_string()); ?>
The resulting URI fails to load since it reads as "http://localhost/CI/index.php?auth/register instead of http://localhost/CI/index.php/auth/register
But, if I modify it to:
<?php echo form_open("/".$this->uri->uri_string()); ?>
all is well. But this is now how it was meant to work! What did I miss?
Thanks!
Why not just remove the index.php using .htaccess? That would solve the problem and give you cleaner URL's.
Here't the rewrite I used for my installation of Tank Auth on my localhost.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /~Steve/_sandbox/tank_auth/index.php/$1 [L]
ErrorDocument 404 /index.php

codeigniter 404 on existing controller

I am facing a different problem in codeigniter.
When I try to access the videos page in my site, it will redirect to 404.shtml page. But cvideos.php file exists in my controllers folder.
If I access like this http://domain-name/videos , then it will be redirected like this
//domain-name/500.shtml
And If I access the same page like this //domain-name/videos/myvideos, then then it will be redirected like this
//domain-name/404.shtml
Also, If I change the controller name from videos to some other name like videoss it works fine. Can anyone tell wats the issue.
I used this line in my .htaccess also just for testing. But no use.
RewriteRule ^videos/$ index.php/videoss/ [L]
Your controller needs to be the same name as the class it contains.
hence -
<?php
controller Videos extends Controller {
/* bla */
}
?>
should be saved as:
videos.php in the "controllers" directory.
Nothing else will work.
also your rewrite rule has two "s"'s, but that might be intentional.
and it looks like what you are trying to do with .htaccess can be achieved with CI's routing
Edit: .htaccess
<IfModule mod_rewrite.c>
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]
#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>
please note I did not create this - it was found by scouring the CI forums. It's a rather thorough htaccess however.
Don't forget to set the value of "index.php" to "" in your config.
base_url is case sensitive
localhost/site/controller = c:...\site
localhost/SITE/controller = c:...\SITE
make sure you are not missing .htaccess file in your root directory. Or check for its accuracy. Make sure uri_protocol and base_url are set correctly in config.php.
for sample, i am copying my .htaccess file here
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /your_dir
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
I used this to get rid of index.php in url.
I had a similar problem when transferring a CI site from WAMPP to a LAMPP that someone else had made. It would seem that WAMPP was configured to be case-insensitive, as when I converted all my controller/model/view file names and all php strings containing controller/model/view names to lowercase it worked perfectly.

Resources