Codeigniter URL index.php twice - php

Hi evrybody ‘im new to codeigniter and to MVC model as well,
I need help to get my project working couse i’ve got this issues:
1) i’m in the main page and i clik on the link of the “about” page, the css file does not seems to load.
and even if i include the css in the head section the images are still missing in the page.
2) in the configure file i’ve set the
$config[‘base_url’] = ‘’;
$config[‘index_page’] = ‘index.php’;
now if i’m in the about page and i clik again on the about link the link it’s missing becouse i set the link in the menu:
About
and so the index.php it’s loaded twice: localhost/mywebsite/index.php/index.php/about.
i could set the condition to cut the link if i’m in the page i need but i would like to know if there is a more polite solution
and hope that the solution it’s not to put my hands in to the mod_rewrite .
I’ll like codeigniter because seems to be easy to configure and so really portable.
and even if it’s simple i can’t figure out how to solve this issues
Thank you everybody for your time!

Even i a newbie to CodeIgniter. I was facing the css problem. I added the css files in separate folder located at the root directory. I solved the problem by adding $this->load->helper('url'); in the controller function of the page.

You need to set $config['base_url'] in config.php to http://www.yourdomain.com and provide full path when linking css to the page like this :
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>resources/css/file.css">

just add
> <?php echo base_url();?>
before or or URL link
> (example: <script src="<?php echo
> base_url();?>assets/js/jquery-1.7.1.min.js"></script>)
to load the link to all page and separate the header and footer in separate file which could help you a lot minimize the page content.

Related

Codeigniter bootstrap load only on index.php page

I'm loading bootstrap this way on my view page :
<link rel="stylesheet" href="<? echo base_url('assets/css/bootstrap.min.css')?>">
autoload: $autoload['helper'] = array('url');
configs: $config['base_url'] = 'http://localhost/helloby/';
Below is the path of the controller:
http://localhost/helloby/index.php/login/home
But when I copy the same code at welcome_message view bootstrap loads normally. I don't know why it's happening.
Try using site_url() instead of base_url()
base_url returns the url without index.php
Check if you are loading the bootstrap css in every view, you cant just load it in one view and expect that all other views know about it.
Common way of doing things like this is to create header and footer files that are shared between all views.
I solved the problem, I was reading an e-book of best practice of Codeigniter and the call of bootstrap was a little bit different.
This way : href="<?=base_url('/assets/css/bootstrap.min.css')?>
and working fine!

CodeIgniter: My CSS file in my view not working

hallo I am running CodeIgniter 3.0.6 and this is my directory structure:
/application
/assets
/js
/mycss.css
/system
My default controller is loading this file in the index.php just fine but when i load another page, the whole page loads afresh but although this file is getting loaded, it is not doing what i want it to do. When i view sourcepage, the links are OK. What could be the problem. I am using base_url('assets/js/mycss') to load it
To put it simpler i have my default controller as welcome. In the index() method of this controller i have $this->load->view('template/index'). This works fine. Now if i load the same page in another method, uniserve(), in the same controller my css file does not do what i want it to do (my page layout is distorted) but all other css files are doing well. What is the problem here. Kindly help.
This link provide exact problem and exact code but my beyond.min.css is not working after it loads fine. How can i achieve the same solution provided in php's codeigniter? Thank you:
Why can't I load js and css files on my pages?
You could also use link_tag().
<?= link_tag('assets/js/mycss.css') ?>
will give
<link href="http://yoursite.com/assets/js/mycss.css" rel="stylesheet" type="text/css" />
And make sure that base_url is specified in your config.php file

Wordpress contact form (404 not found)

I created a template on WordPress and I made an html form. It works well in HTML but doesn't work when used on WordPress. It seems that it doesn't find my contact-send.php page and it displays a 404 Error page.
My permalinks were on default and it didn't work.
Does anyone know how to fix this?
If any of my code is needed, I'll post it. I just didn't because I think it's not a code error once it doesn't find contact-send.php.
Use an absolute URL for the target of your form instead of just action="contact-send.php".
But unless you have particularly unusual requirements for your contact form, you will likely have better results using one of the many popular contact form plugins like Contact Form 7.
Using a well-maintained plugin ensures stability, and more importantly, security. Don't reinvent the wheel if you don't have to.
Your problem can be caused due to 3 reasons.
Giving wrong path in action tag. Using <?php echo get_template_directory_uri(); ?>/contact-send.php will solve this problem.
Missing contact-send.php page in the themes folder. This problem can be solve by adding the page to the themes folder.
Improper .htaccess file. This can be solved by recreating the code for your .htaccess file from Dashboard > Permalinks and paste it in the .htaccess file in the WordPress root directory.
I am giving the explanation in the assumption that your template file is directly in the themes folder.
Add <?php echo get_template_directory_uri(); ?>/contact-send.php. When you write contact-send.php only then it don't find your file which is in your theme. So use this <?php echo get_template_directory_uri(); ?>/contact-send.php in form action. This change may be helpful.

Relative pathing

Creating a wordpress sight for work to display some info. For convience i have included the following php code
<?php include 'wp-includes/fancyboxstart.php'; ?>
that file loads all the JS, and defines the div id for my fancybox img display. Recently i have changed the permalinks on my WordPress to get rid of the awful page=1 html links. Now i know to fix all my images simply by adding a "/" to the front on my img srcs. My problem is now that i have changed the permalinks it is no longer loading the JS page from above and my Image displayer no longer works =[
I have tried directly linking to it with
`<?php include 'http://premiumshotguns.com/wp-includes/fancyboxstart.php'; ?>`
but no luck. I know it's probably a simple fix but i am not seeing it! any help would be appreciated!
You probably need to include your theme path.
<?php include bloginfo('template_directory').'/wp-includes/fancyboxstart.php'; ?>

Parent directories and PHP

I really hope there's a simple solution to this.
<?php include("header.php"); ?>
Let's say I have a php header in my root folder simply titled header.php. In that header there is a link back to the home page, main.php, and main.php is also located on the root. No problem so far. Here's what header.php looks like. Simple stuff, right?
<link href="style.css" rel="stylesheet" type="text/css" />
<div id="headerwrap">
<div id="linkbox">
<img src="images/mainlogo.png" />
</div><!-- End linkbox -->
</div>
However, let's say I have other pages in subdirectories. Subpage.php is located in a child directory of the root, and so it has to look back to the root to get the included header.php.
<?php include("../header.php"); ?>
That wouldn't be a big deal, except that header.php links back to main.php and also style sheets, none of which are in *subpage.php's directory, thus causing an error when someone on Subpage tries to get back to Main via the link in the header.
I'm just hoping there's a simple way to make this work, and that I don't have to copy and redirect all includes into every subdirectory. Also, there are too many pages to really reasonably include them all on the root. Sorry if this answer is posted elsewhere; I've looked and just have no real idea what I'm looking for. Thanks for your help. Hope all that makes sense.
You could just hard code main.php's path within header.php:
<img src="http://website.com/images/mainlogo.png" />
As opposed to a php prob this seems to be an html prob..
Your links should be relative links with a preceding / i.e.
Text
instead of
Text
how about using absolute links. header.php should also reference main.php absolutely, then there should be no troubles:
<?php include($_SERVER['DOCUMENT_ROOT'].'/header.php"); ?>
You can use the base html tag:
<base href="http://yoursite.com/" />
This way you can use that url as the base for all your links/stylesheets/images and you don't need to worry if they're in a subdirectory.
the best thing to do is to get in the habit of using
$_SERVER['DOCUMENT_ROOT']
that way you have no confusion as to what directory you're in, etc.
so including your header for example would be as simple as :
include $_SERVER['DOCUMENT_ROOT'] . "/header.php";

Categories