I have create a controller in codeigniter. The problem is that when I hit the controller name and function name in url then Its give me error that 404 not found. I am new to codeigniter and I did not understand where I am going wrong
Here is my controller
<?php
if(!defined('BASEPATH')) exit('No direct script access allowed');
class Home extends CI_Controller{
function __construct(){
parent::__construct();
}
function you(){
$this->load->view('home_view');
}
}
?>
and my view is like this
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My First CodeIgniter Practice</title>
</head>
<body>
<h1> HELLO CI Buddy...!</h1>
</body>
</html>
I am creating my first project on codeigniter and I stuck in this problem.I already try most of the solution from the stackoverflow and after that I asking this question. So Its my request not to add this question to duplicate. I want solution for my problem. any help is appreciable
Thanks
I think there might be problem with .htaccess file. Do you have .htaccess file in your main project directory and is that written like following ?? If not make that so..
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php/$1 [L]
Your issue may be due to any of the following reason
First letter of your controller file name should be in capital letter ie Home.php .
Please check your home page file name
Use the URL localhost/w3crud/index.php/home/you
if the issue is in your url then edit your .htaccess file
While thinking about this problem I wonder this might happened to starters like me
Suppose we have the project in a folder named codeigniter. so when typing the url we type something like this localhost/codeigniter/ and it shows the welcome message.But it automatically adds index.php defined in config.php (line 38) after the url like this localhost/codeigniter/index.php. So if you don't have mod_rewrite written in .htaccess file don't worry, try this url
localhost/codeigniter/index.php/home/you
in your case home.php is the controller file and you is the method here
Are you running your project on a live server? If yes, then make sure the filename of your controller starts with a upper case letter. It might seem like a silly answer but mind it that I myself spent more than five hours trying to fix the same problem.
Please try with following
a) Create member function index() in controller and check
b) Which url yor are checking?
b.1) http://localhost/yourproject/index.php/home/you
(localhot: is your server url, yourproject: your project folder, home = your controller file i.e. Home.php and you: your member function.
Try as following
<?php
if(!defined('BASEPATH')) exit('No direct script access allowed');
class Home extends CI_Controller{
public function __construct(){
parent::__construct();
}
public function index(){
$this->load->view('home_view');
}
}
?>
and make sure your home_view.php file exist with your code in application/views directory. Now you may run URL http://localhost/w3crud/home/index to see the desired output
There are a lot of possible causes as to why it is happening. In my case, the cause is about the use of underscores in naming a controller e.g. My_Custom_Controller
routes.php (problematic)
$route['translate_uri_dashes'] = FALSE;
$route['my-custom-path'] = 'my_Custom_Controller/landing';
So, I was able to fix it by renaming the controller into Mycustomcontroller then that was the only time it worked.
routes.php (functional)
$route['translate_uri_dashes'] = FALSE;
$route['my-custom-path'] = 'mycustomcontroller/landing';
The naming doesn't follow the suggested naming convention of CodeIgniter but it definitely solved the issue for me.
If you have your CI in a subfolder, let say c:/xampp/htdocs/somemap/ci
Change your .htaccess to
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /ci/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /ci/index.php [L]
</IfModule>
Please note the /ci/
Related
new at codeigniter, trying simple code to load bootstrap css files with base_url() function.tried some answers on stackoverflow,but issue not solved.
my view name is.... articles_list.php
my controller name... user.php
i edit config.php as follow 'localhost/ci';
i edit autoload.php as follow i load url helper in autoload.php
articles_list.php (loading css in view file)
<link rel="stylesheet" type="text/css" href="<?php echo base_url('assets/css/bootstrap.css') ?>" >
user.php(controller)
$this->load->helper('url');
$this->load->view('public/articles_list');
when i run my view file, css is not loading, when i check view source it should give me both stylesheet url and link address as "localhost/ci/assets/css/bootstrap.css" but when i see view source it show <link href="localhost/ci/assets/css/bootstrap.css"> and when mouse over at link it shows me localhost/ci/localhost/ci/assets/css/bootstrap.css link address. please
help me to solve this issue and help me to learn codeigniter.
Make sure you set the base_url right in application/config/config.php file:
$config['base_url'] = 'http://localhost/ci/';
And of course make sure to use the correct .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
i did everything to load a view from home page, but site url is not working here are the files
view that i am loading is fundme-explore.php
in this i am using site url link in the explore tag
<div class="navv">
<ul class="nav navbar-nav">
<li><a class="navbar-brand" id="hm" href = "<?php echo site_url('Welcome/explore') ?>">Explore</a></li>
<li><a class="navbar-brand" id="br" href = "start_a_project.html" >Start a project</a></li>
<li><a class="navbar-brand" id="ab" href = "About_Us.html" >About us </a>
</li>
</ul>
Here is my controller welcome.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
function __construct() {
parent::__construct();
// Load url helper
$this->load->helper('url');
}
public function index()
{
$this->load->view('Fudme-home.php');
}
public function explore()
{
$this->load->view('fundme-explore');
}
}
?>
here is my route file
$route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['welcome/explore/'] = 'welcome/explore';
here is my .htaccess file
<IfModule authz_core_module>
Require all denied
</IfModule>
<IfModule !authz_core_module>
Deny from all
</IfModule>
and here is the picture of error i am getting
this appear when load explore view from main page
i did everthing what tutorials or in other guides mentioned still uable to detect whats wrong kindly help me if u know.
I think you need to change in your htaccess with following code :
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /YOUR_FOLDER/index.php?/$1 [QSA,L]
</IfModule>
In application/config/config.php make sure your ‘base_url’ config value is not empty. Typically this will be your base URL, with a trailing slash.
$config['base_url'] = "http://example.com/";
Also make sure that the file name starts with an uppercase letter. welcome.php should be Welcome.php.
Not part of your problem, but something you need to understand: You do not need and should delete the following route.
$route['welcome/explore/'] = 'welcome/explore';
There is a one-to-one relationship between a URL string and its corresponding controller and method following the pattern: domain/controller/method
The only time you need a $route is when you want to remap the relationship. Read this carefully for more detail.
Given the controller you show, the URL http://example.com/welcome/explore/ will call the explore method of the Welcome class without any $route being set - assuming Codeigniter is correctly configured.
I am trying to open a page on clicking on a link in my codeigniter application. This is the snippet of my attempt
at the controller level this is snippet
//load return policy
function returnpolicy()
{
$this->load->view("return_policy");
}
at the view level this is the snippet
<div class="toggle">
Return Policy
</div>
on clicking on the link it does not navigate to the page. please what am I missing. am new to codeigniter
You should understand the difference between site_url and base_url first
echo base_url(); // http://example.com/website
echo site_url(); // http://example.com/website/index.php
You can rewrite it as follows :
<?php echo site_url('controller/method');?>
In HMVC
<?php echo site_url('module/controller/method');?>
So in your case
Return Policy
you can use the URL helper this way to generate an <a> tag
anchor(uri segments, text, attributes)
So... to use it...
<?php echo anchor('gotopolicy/returnpolicy', 'Return Policy', 'class="toggle-title"') ?>
Possible issue could be of htaccess,
create a file .htaccess in your root CI folder
and add below contents to it
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Make $config['index_page'] = "";
try to remove class="toggle-title"
or try this
<div >
Return Policy
</div>
I'm new in laravel. However, I'm created blade templates and integrate with my offline index webpage. It consists of signin.html and signout.html. So below is the structure way of managing my files:
-views
--account
---signin.blade.php
---signup.blade.php
--includes
---head.blade.php
---footer.blade.php
--layouts
---master.blade.php
--home.blade.php
Home.blade.php
#extends('layouts.master');
Master.blade.php
<!DOCTYPE html>
<html>
<head>
#include('includes.head');
</head>
<body class="bg-info">
<!-- #include('includes.navigation'); -->
<!-- #extends('account.signin'); -->
<!-- #yield('content') -->
<!-- #yield('content') -->
#include('includes.footer');
</body>
</html>
The following two files will output the signin form in the page. I have no idea how they get into it. I didn't include anything. My public folder :
--assets
---css
---fonts
---images
---js
--index.php
--.htacess
Index.php
require __DIR__.'/../bootstrap/autoload.php';
$app = require_once __DIR__.'/../bootstrap/start.php';
$app->run();
$app->shutdown();
.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Route
Route::get('/', array (
'as' => 'home',
'uses' => 'HomeController#home'
));
Home Controller
public function home() {
return View::make('home');
}
Now if I'm open-up my localhost, View [includes.master] not found. Perhaps my storage folder still contains the template codes, but I tried to delete, it keep generate a new one.
Another problem is when I adding #extends('includes.master') into signin.blade.php or singup.blade.php at the top.
The localhost and localhost/account/signin or localhost/account/register will be Internal Server Error: 500 .
Well, Let me tell you something. What's the need to include your header from an external folder? Please follow this, your master layout should be like this:
<!DOCTYPE html>
<html>
<head>
//put your codes here , not the include function
</head>
<body class="bg-info">
#include('includes.navigation');
#extends('account.signin');
#yield('content')
#include('includes.footer');
</body>
</html>
home.blade.php should be like this:
#extends(layouts.master)
#section('content')
<p> Hello, this works </p>
#stop
Now let me if you need any further help.
Check views folder permissions. In my case there was a problem.
For this folder and all the files inside permissions should be 755.
Had the same issue, think that has something to do with blades caching of the view dir. I fixed it by changing the #extends(example.master) to another template and then back to wanted path. Worked without doing anything else, but as always first try php artisan view:clear.
Greets, Pat
I am trying to apply css in the Zend Framework. My css file is in public/css/layout.css. First of all I added the following code lines in bootstrap.php:
protected function _initPlaceholders()
{
$this->bootstrap('View');
$view = $this->getResource('View');
$view->doctype('XHTML1_STRICT');
// Set the initial title and separator:
$view->headTitle('My Site')
->setSeparator(' :: ');
// Set the initial stylesheet:
$view->headLink()->prependStylesheet('../../css/layout.css');
}
Which simply specifies the title and stylesheet to be used. Then in layout.phtml I add the following code:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<?php
echo $this->headTitle();
echo $this->headScript();
// add a link to the site style sheet
echo '';
echo $this->headLink();
?>
</head>
Which simply adds link of the stylesheet specified in bootstrap.php.
But when I run the project then I am getting the form without css. Why is this? When I check the css with Firebug in a Mozilla browser it says:
<h3>Exception information:</h3>
<p>
<b>Message:</b> Invalid controller specified (css) </p>
<h3>Stack trace:</h3>
<h3>Request Parameters:</h3>
<pre>array (
'controller' => 'css',
'action' => 'layout.css',
'module' => 'default',
) </pre>
Please help me out to resolve this issue.
Try
$view->headLink()->prependStylesheet('/css/layout.css');
this should help.
Do you have this code on your /public/.htaccess file?
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
If you don't have the first 4 lines, this file will redirect your request of "css/layout.css" to index.php and then, Zend will interpret it as a link for a controller -> action.
If you have this file, make sure that mod_rewrite is enabled on your server.
And you sould put your link as "akond" said.
Good luck =)
This helped me:
Zend_Controller tries to execute my stylesheets as controller
[update]
Ok, just added the following line to my .htaccess file and all works as expected now...
RewriteRule !.(js|ico|txt|gif|jpg|png|css|htc|swf|htm)$ index.php
but then I found this one:
http://devzone.zend.com/1651/managing-css-and-javascript-files-within-a-zend-framework-app/