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.
Related
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 have a menu like:
<ul>
<li>Home</li>
<li>Contect</li>
<li>References</li>
</ul>
And i would like to tell that the / use home.php, the /contact get method use the contact.php and the /references use the references.php and of course th active class also change when we are at the contact menupoint and so on....
Thanks for the help! Im new with php sorr..
Easiest way to do it:
create a file with a name .htaccess
RewriteEngine on
RewriteRule ^/([^/\.]+)/?$ index.php?page=$1 [L]
if your files are under another folder like `includes/contact.php``
RewriteEngine on
RewriteRule ^/includes/([^/\.]+)/?$ index.php?page=$1 [L]
getting your page via 'GET' in your index.php
$page = $_GET['page']; //contact.php
and test:
Contact
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/
I am working with codeigniter but i dont know how to put link to another page. My controller filename is aboutus.php. I gave a link like
AboutUs
My base url is
$config['base_url'] = "http://localhost/project/";
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
But above url not working. I write a url directly in browser and hit like
http://localhost/project/index.php/aboutus then its working fine. how to give a url? i am confused.
base_url() will echo:
http://localhost/project
where as site_url() will echo:
http://localhost/project/index.php
You want to get to http://localhost/project/index.php/aboutus but with base_url() you're only getting to http://localhost/project/aboutus which is giving you the error.
You can do two things,
this:
AboutUs
which means adding the index.php before aboutus
or this:
AboutUs
which means changing base_url() to site_url().
Make sure that you are loading the helper in the controller:
$this->load->helper(url);
Or in application/config/autoload.php go to the line which says:
$autoload['helper'] = array();
and do this:
$autoload['helper'] = array('url');
and it will be included in every controller you now have.
If you have short tags enabled you can write your a tag like this:
About Us
or if you have the url helper you can write it like this:
echo anchor('aboutus', 'About Us', 'title="About Us"');
Try site_url() instead of base_url() so index.php will not be skipped
AboutUs
https://ellislab.com/codeigniter/user-guide/helpers/url_helper.html
Also, make sure that url helper is loaded.
$this->load->helper('url'); //can also be done in config/autoload.php
Before using CI functions base_url() and site_url()
you need to load URL helper either in autoload.php or in controller itself.
If you have short tags enabled in PHP you can also write it link that:
Link Text
Use this .htaccess on your base folder
RewriteEngine on
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
If YOu still not get the result Please enable mod_rewrite in your apache server
your Project URL is look like you didn't enabled php short tags. Thats not a problem. just try this code:
About Us
I am using code igniter 1.7.3 and my static html files are resides under "businesscaliber\system\application\views" folder. Also I am using Jquery Boxy plugin. but when I click on Remote content link it is not going to display partial.html content.
<a href='/partial.html' class='boxy' title='AJAX Content Demo'>Remote content (partial.html)</a>
<script type='text/javascript'>
$(function() {
$('.boxy').boxy();
});
</script>
Make sure your partial.html file is in the root directory and if your using .htaccess to rewrite URL's try this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
for that you need to have a static html files in the root directory
ex
Root
-system [DIR]
-aplication [DIR]
-staticHtmlDir [DIR]
--partial.html [FILE]
Your url should be as follows;
<a href='staticHtmlDir/partial.html' class='boxy' title='AJAX Content Demo'>Remote content (partial.html)</a>
OR YOU CAN THIS WAY
controller file
<?php
class MyClass extends Controller {
public function MyClass() {
parent::Controller();
}
public function showRemoteHtml() {
$this->load->view('partial');
}
}
/* End of file Myclass.php */
Your url should be as follows;
<a href="<?php echo site_url('Myclass/showRemoteHtml'); ?>" class='boxy' title='AJAX Content Demo'>Remote content (partial.html)</a>