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
Related
Moved existing codeigniter app to a new server to perform some code updates. Everything is working correctly except any method that uses POST returns 404.
For example:
function export_xls(){
echo "HERE";
if($this->input->post()){
I'll be able to hit the echo but it will then 404 at
$this->input->post()
I've tried changing base_url in config.php and different things in htaccess to see if that helps but nothing has proven successful.
All other functions where post values are not being called work perfectly.
Live url (where everything works) is http://admin.xxxxxx.com and dev is http://crm-admin.srv-y7z9u.xxxxxxx.com if that provides any insight.
Try to check for some issues that can get in the way.
First see if the link is being directed to the page correctly, then follow some steps that can help you:
Check base_url in your project settings.
Make sure you have not entered the wrong direction, as is quite common: http://crm-admin.srv-y7z9u.xxxxxxx.com/saveForm
see also $.post to Codeigniter Controller/Method 404 Page Not Found
I am currently working with some legacy flash files that submit POST data based on some actions. Problem is I am unable to edit the flash file and flash seems to be submitting to the controller method the flash file is currently on + index.php.
It is fine that its submitting here, I'm just trying to figure out a way to catch it. Everything I attempt continues to return a 'NotFoundHttpException'.
I am currently trying to catch it with:
public function postMethod()
{
}
Any suggestions?
Is the route making it past your htaccess intact? Can you show your routes file? If the route is coming through OK surely you can just match RouteWithFlashFile/index.php to a method in your controller. Something like this:
Route::post('RouteWithFlashFile/index.php', 'MyController#processFlash');
If that doesnt work, you might have to look at reworking your htaccess to map the route to something else. I will confess this is all speculation as I've never stuck index.php in the middle of a route before.
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? :(
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');
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