trying to open a page using a link codeigniter php - php

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>

Related

view is not loading using site-url in codeigniter

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.

How to redirect urls from menu in php?

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

Displaying dynamic content based on browser location

I had an idea of writing a page template in my index.php where the content section of the page will include the content dynamically by determining what url the browser is at and getting the content page based on that. There's a few issues though:
<?php
// /index.php
?>
<!-- html tags and menu/layout divs as needed go here -->
<section id="content">
<?php
function curPageURL()
{
$page = substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
return $page;
}
$page = curPageURL();
switch ($page)
{
case "index.php":
include_once("includes/home.php");
break;
}
?>
</section>
<!-- footer and such goes here -->
Although this works, I'm having trouble applying the concept further. I just can't seem to get my head around how the navigation should work or how to apply this concept to other pages in my site...
If anyone can advise, I'd really appreciate it.
You could use a .htaccess file (put in the same directory as index.php).
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?uri=$1 [L,QSA]
And then in index.php you can get the page with:
$page = $_GET['uri'];
So if you user goes to example.com/home then the page variable will be set to home.

mod_rewrite rewriterule?

hello i have an anchor on my site. by calling my site the url will be:
http://site.com/page.php
by clicking a button the url will display an url that i would like to hide:
http://site.com/page.php#1
now i have found out that i can change this by using mod_rewrite tool. i tried this rule without success:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^(.*)\.html$
RewriteRule ^.*\.html$ %1.php [L]
for calling the page as html or php and to hide the #1 behind the .php
RewriteRule ^(.*)$ ./php#1=php$1
i really would appreciate if there is someone who could give me advise on how to solve this. thanks a lot.
You cannot achieve this via mod_rewrite.
URL after # are not passed through server.
If you still want to achieve this, you may want to look into doing it via JavaScript:
Check this out
JavaScript:
function scrollHere() {
// Scroll to the anchor
//(you may need to look for some script to achieve this)
return false; // to prevent URL overwriting
}
One such script is this jQuery.scrollTo.
The hashtag is never sent to the server, thus you simply cannot create a rule, that based on it.
You can do something like this to remove # tag.
Your text.
So when you write "javascript:void(0);" in href attribute of a tag and thats it.
HTML
<a href='page'>Home Page</a>
<a href='page/1'>Page 1</a>
<a href='page/2'>Page 2</a>
<a href='page/3'>Page 3</a>
Rewriting as
RewriteRule ^$ page.php [L]
RewriteRule ^([a-z]+)/?([0-9]*)/?$ page.php?index=$2 [L]
And check for index in php
<?php
if (isset($_GET['index']))
{
$pageNo =$_GET['index'];
}
//based on page NO display contents
?>

Not able to open static html file content using Jquery Boxy along with Code igniter

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>

Categories