CodeIgniter allways unable load file as header in the page - php

I have a problem when try to code something with CodeIgniter.
Always appear in the title of the tab "Error", and in the body of the page appear:
<h1>Error</h1>
unable to load the requested file:
Then appear all the things I had programed correctly.
.php
And this is the structure of all my pages... The controllers works OK, the models works OK, and the views are as I want... except this error...
So I think I change something in the configuration or other place... but I cannot find the mistake...
Any ideas?

Could be a path error. Look carefully and check that you are using this pattern
$this->load->view('path'); // please note the " ' " that I used.
And this if you want to pass parameters to your view:
$data['something']=$something;
$this->load->view('content', $data);
I'm pretty sure you're not passing your data correctly to the view.
Yo have to consider that default root path of view function is application/view, so construct the path consistently.
If that does not work a bit of your coding may be useful.
Hope this help.

Related

Passing PHP URL variables leads to Page Not Found

I have an image that is supposed to redirect to another page when it's clicked. It also "sends" two variables to the page, s and n.
echo "<a href='../?change-preference&s=up&n=".$element."'>
<img src='..media/images/sort-up.png'>
</a>";
On the change-preference page I get the two variables like so:
$s=$_REQUEST['s'];
$n=$_REQUEST['n'];
My problem is that I get a "Page Not Found" error.
Also, if I try to directly access the page it works, but only if I type this:
www.example.com/preference/change-preference
and not if I try it with :
www.example.com/preference/change-preference&s=up&n=999
Any help would be appreciated!
You should use:
www.example.com/preference/change-preference?s=up&n=999
The ? is being used in the incorrect place when you are building your link.
You need to build your link as follows:
$element = 900;
echo "<a href='../change-preference?s=up&n=" . $element ."'><img src='..media/images/sort-up.png'></a>";
This will give you:
www.example.com/preference/change-preference?s=up&n=900
And in the following link from your question the ? is missing, which will not work:
www.example.com/preference/change-preference&s=up&n=999
First you are using ? in the incorrect place as Daniel_ZA pointed out or you have typed incorrectly on your question the url that actually works. For this answer I will assume that it is the first case.
Second, do you have a php file named "change-preferences" without the .php extension? It is being parsed via php. I think probably not. So you should have a folder named change-preferences then and a file named index.php inside it right?
Well, that's the reason change-preference?s=up&n=900 redirects to change-preference\?s=up&n=900. Because you are accessing the index file for that address and not directly a file. It should work fine however.
If it still return a 404 (Page not Found) error then it's probably something that you haven't include in your question that isn't well configured or is having a bad behavior. Please try a simpler setup (create a new folder with only the minimal necessary to execute the url) or provide more information on your question.
Well.. I didn't mention that I am working with Wordpress because I thought this was 100% PHP question. It appears that "s" is a reserved term in Wordpress causing a 404 error. Changing the "s" fixed the problem. I am living this answer here in case that some one else working on Wordpress finds him/her self in the same position. Al of the reserved terms.

PHP CodeIgniter URL navigation issue

I am new to CodeIgniter and also have average PHP knowledge. Just started learning CodeIgniter last week and having a basic problem which i can't overcome. my development environment is (OS,PHPStorm,MAMP,APACHE). CI project root is http://localhost:63342/CodeIgniter/ and this address loads my 'default_controller' (login.php in Controllers folder). this controller redirect me to my view "$this->load->view('login_view');". in my view i have a form with this line: which supposed to take me to my form.php in Controller upon the form being submitted but it does not! when i submit i am taken to a url : http://127.0.0.1/CodeIgniter/form with error message "connection attempt to 127.0.0.1 was rejected.".
Also when i try to type a url (i.e. BASE_URL()./index.php/form) or amy other URL in fact, i get errors too. i was under impression that navigating through pages in CI is as simple as typing the name of the file and the method in it in my Controller folder. what am i missing here? any attempt to navigation through URL i get "404 Not Found" error. i am sure i am missing something very simple here but i can't figure out what. i have read the documentations and search the web and no answer is found. i have changed the .htdaccess in root, tried the enable mode in Apache, done all the necessary changes in Config.php , routes.php etc. i would appreciated it if you can tell what am i doing wrong here. i wasn't expecting getting started with CI to be this hard :s
cheers
It seems you "loose" the port (63342) when you redirect. What is the action of your form? If this is an url like "http://localhost/CodeIgniter/form", you should add the port : http://localhost:63342/CodeIgniter/form
You can output set your login form's action by using the URL helper.
site_url('form')
http://www.codeigniter.com/user_guide/helpers/url_helper.html?highlight=site_url#site_url

Problems reading data from Codeigniter Template Partials, and with controller redirection

I have two unrelated Codeigniter problems:
(a) I am trying to redirect a user to the dashboard after logging in successfully. i.e. from controller "auth" to controller "dashboard". For some odd reason, it keeps redirecting to auth/dashboard (404 error since it does not exist).
This is what I did:
//Within the auth controller
if ($this->auth->login($username, $password)) //Auth->login returns boolean
{
redirect('/dashboard', 'refresh');
# redirect('/dashboard', 'location'); // I tried this too
# redirect('/dashboard/index', 'refresh'); // I also tried this!
}
What am I doing wrong, please? It just keeps redirecting to auth/dashboard
(b) I am using Phil Sturgeon's brilliant Codeigniter Template library (without a Parser) and I am unable to receive data sent into a partials file. This data is ONLY needed by the partials file. I have been over the (unfortunately sparse) library documentation, S/O posts on the topic, and also the CI forums to no avail, there seems to be no clear-cut example showing how a partial receives data that a controller assigns to it.
This is how I have been doing it. Please tell me what I must be doing wrong.
// In the controller page
$this->data['user'] = array('info' => 'username', 'value' => 'Cogicero');
$this->data['prefs'] = array('foo' => 'bar');
$this->template
->set_partial('header', 'partials/header', $this->data)
->set_layout('blog')
->build('foobar_view');
And
//In the header partials page
<?php
/* snip */
print_r($data);
print_r($prefs);
print_r($user);
echo $user["info"];
echo $prefs["foo"];
?>
All the above produce "array does not exist" or "undefined variable" errors! How am I meant to be receiving data within the partials view file?
Thanks
EDIT:
Working on a tight deadline so with no solution in sight, I had to abandon Phil Sturgeon's template library and pick up Jens Segers' instead. http://www.jenssegers.be/blog/25/Codeigniter-template-library
It is a little similar to Phil's but for some reason the partials are receiving and rendering my data properly. Also, Sergers' template library is very well documented. All is fine now, so I'll accept my own answer to problem (a). Thanks everyone.
(a) So after a lot of fiddling around I have solved the first problem i.e. the redirects.
In the config file, we have
| If this is not set then CodeIgniter will guess the protocol, domain and
| path to your installation.
|
*/
$config['base_url']=
Apparently, I didn't set a base URL because I'm still on a development local server, I was going to set it to the www address when I upload to the test server. Codeigniter had been guessing all along, but the guess didn't work for my authentication redirects. I set the base url and all redirects were fine.
(b) Now, to see why the partial views are not receiving data. Any help please? :(

Codeigniter Loading external site in default controller

I'm not able to figure this out on my own so here I am asking for your help.
How do I load a website that I already made as a view in the code igniter default controller?
I put my website under a folder name site, and in the default controller I loaded the view site/index , but then in my site there are problems with the includes and redirects... I don't know why, I guess the way the site usually works with redirecting isn't compatible with code igniter style
edit: I guess I would have to turn off CI engine for this site, but I don't know why, because I would still need codeingiter to manage other parts of my application
"CodeIgniter can be told to load a default controller when a URI is not present, as will be the case when only your site root URL is requested. To specify a default controller, open your application/config/routes.php file and set this variable:
$route['default_controller'] = 'Blog';
Where Blog is the name of the controller class you want used. If you now load your main index.php file without specifying any URI segments you'll see your Hello World message by default."
http://codeigniter.com/user_guide/general/controllers.html
fragment copied from that link , you should put the controllers classname in that config, not the view
I guess it's better to choose one of these options:
Modify the existing site to a CodeIgniter site.
Keep your site separate from the CodeIgniter site, and just link between the two sites.
The way you are trying to do it seems very useless and causing a lot of extra trouble.
You can simply use the redirect function in your controller. If you supply a full URL you can go to any other page. You will, of course, leave your CI app.
redirect('http://www.example.net/page_in_external_site/');
Try using the APPPATH constant when defining the paths for the includes.
I know it's an old question, but you can try using a view template with an iframe, and you can pass the URL to the src property of the iframe. That way you can display your site inside a view, but still can't get access to the vars passed to the view from your site.
In system/Core/Loader.php change the line 141 to look like this:
$this->_ci_view_paths = array(APPPATH . 'views/' => TRUE, FCPATH => TRUE);
and to get the view is simple:
$this->load->view('application/ PATH_TO_VIEW');

Need help with Code Igniter [did not found page created]

so I hope someone would help me.
My first page is leave_app.php. In this page I put a link to apply leave, using the normal code:
New Leave Application
However the link didn't display as I had wished for.
"The requested URL /ci/add.php was not found on this server." and the link in the browser leads to this "http://localhost/ci/add.php".
I don't know why the server didn't find the page. I already made add.php page, also add at the leave_app controller the function add().
In the config.php file I put $config['index_page'] = '';
I have asked around but no one can help. I have already surfed around, but still don't know how to solve.
The beauty of Codeigniter is to rewrite urls in a clean manner, so all things go through index.php and the corresponding controller is loaded
Try accessing it like so:
/ci/index.php/add
Make sure your controller is in application\controllers\add.php and named Class Add

Categories