Html template integration with codeIgniter - php

I'm currently working with codeIgniter framework and the problem i'm facing is with template integration with it. In view pages the links aren't working.Like if i've to navigate using
<p>Contact
i changed this with
<li><strong>Contact</strong></li>
And this:
Contact</li>
but nothing happens. May i know how to navigate to other views using these menue tags?? I've also loaded views from controller but the result is same.
Thanks in advance..

What do you mean by saying that nothing happens? do you get any error? does the page even redirect? if the page redirects and you still cannot see any errors put this code in the head of your index.php for debugging purpose: error_reporting(E_ALL); ini_set('display_errors', '1'); and watch the errors you are getting.
There could be a few reasons for it:
you didn't loaded the Helper: $this->load->helper('url');
you should configure the base_url in your config.php: $config['base_url'] = '';

Related

Codeigniter doesn't load view correctly

I have a codeigniter project that is already up and running perfectly on the client server, now after I changed my laptop and installed xammp 1.8.2 the project is not working correctly,
the index page works just fine, and when I try to log in it only displays these two lines
load->view('header');?>
load->view('side_menu'); ?>
These two lines are the only php code in the view Home.php ,so the problem is that load view function in the controller loads the view "Home.php" but only displays the php code
The hierarchy is:
application
controller
main_controller.php
view
home.php
and attached a screen shot of the displaying
Could any one help me with that???
Thanks in advance
Given your example, You will need to open your php document with <?php and end it with ?> (not on each line as you have it.)
You will also need to use $this from the controller class.
<?php
$this->load->view('header');
$this->load->view('side_menu');
?>

Codeigniter URL index.php twice

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.

yii layout no visible changes

I tried force refresh on my browser and change the name of the layout from main.php to main_.php still nothing happened. No visible effect, no error, no nothing.
I'm sure missing a small detail here. Can anyone guide a beginner in this problem?
Version: Yii 1.1.10
check the main layout in site/layouts and in themes/layouts too, definitely there are more version of it.
For you the yii debug toolbar 3rd party extension would definitely help to identify the layout file that is used, install it.
You can control which layout files is included with the controller's $layout property
You need to tell your controller to use layouts from the current module, with single slash notation eg : $layout = '/site/myview' read more about this at: getLayoutFile()

Display a view for 404 error in CodeIgniter

The CodeIgniter has a very simple default error 404 message:
404 Page Not Found
The page you requested was not found.
Instead of using this error message on totally blank page, I want to wrap this message in between my header and footer view, so that the error message have similar look to the other pages.
For that purpose, I have created an error view? For example:
my404_view.php
<? $this->load->view('header'); ?>
404 Page Not Found
The page you requested was not found.
<? $this->load->view('footer'); ?>
Now, How can I use this my404_view.php as a default view to display 404 messages instead of using the CodeIgniter default error message.
You should change your routes.php. For example:
in application/config/routes.php
$route['404_override'] = 'welcome/_404';
in application/controllers/welcome.php
function _404(){
$this->load->view("my404_view");
}
And this should be sufficient in the current version of CI.
Including headers and footers in the default error 404 page seems to be a common problem for CodeIgniter users. I would like to add this link: Simon Emms's comments at http://www.simonemms.com/2011/05/06/codeigniters-404-override-problem/ because he describes the problem so clearly.
I have tried the suggestions at http://maestric.com/doc/php/codeigniter_404 and played around with Simon Emms's ideas, and others, but just can't implement them. I'm a bit of a novice at PHP and CodeIgniter, so that might be because of ignorance. That said, it is difficult to ensure that you put the suggested subclasses in the right places and configure, for instance, routes.php correctly. After 3 days of trying the various rather complicated ideas, it occurred to me that I could just use an include statement in the default error 404 page. The only difficulty was figuring out the path to pass to the include statement.
In /system/core/Exceptions.php line 146, I found the CodeIgniter developers use APPPATH. You then just have to append the path to the header and footer pages you want to include.
My new default error 404 page now looks like this:
<?php
include APPPATH.'/views/templates/header.php';
?>
<div id="container">
<h1><?php echo $heading; ?></h1>
<?php echo $message; ?>
</div>
<?php
include APPPATH.'/views/templates/footer.php';
?>
This seems a much easier solution to me than trying to change the core classes in CodeIgniter.
There is quite a bit of information on this.
http://maestric.com/doc/php/codeigniter_404
http://www.nickyeoman.com/blog/apache/90-htaccess-404-page
http://hasitha.posterous.com/customising-error-pages-on-codeigniter (archived)

CodeIgniter 1.7 reCaptcha Help

http://codeigniter.com/wiki/ReCAPTCHA/
Okay. So I download the code. Move all the files to the appropriate folders. Set the keys in the config/recaptcha.php file. Then where I have my form submit logic I put in the
$this->form_validation->run()
function.
Then in the HTML I do what?? I need to display the captcha for user input. I see google's code for adding the php recaptcha into non-code igniter documents, but I'm not sure which parts of that are relevant. And I'm not sure how I'm supposed to be making calls to particular files. Right now
<? $this->load->view('recaptcha.php');
$publickey = "thekeynumbersandgibberish";
echo get_html($publickey);
?>
this currently breaks my HTML page, I figure I'm not calling the file and function correctly using code igniter syntax. What is the proper syntax? This was not included in the code igniter documentation.
Insight would be appreciated.
You need to call this in your controller first
//In your Controller
$data['recaptcha'] = this->recaptcha->get_html();
$this->load->view('my_view',$data); //try it with the test page first
//In your View
$this->load->view('recaptcha.php');
The instructions in the wiki are pretty straightforward. Don't load the files in the view. Assign the HTML in the controller.
This is the normal process when working on MVC.
There's a basic CI tutorial here : http://net.tutsplus.com/tutorials/php/codeigniter-basics/

Categories