Codeigniter controller method 404 error - php

I cloned a copy of Codeigniter from github today using this link: https://github.com/bcit-ci/CodeIgniter.git. I am currently running MAMP setup so that http://localhost:8888 points to my htdocs folder. My root folder is called 'time'. When I go to http://localhost:8888/time/index.php, I do see the Codeigniter welcome page. Also, I can go tohttp://localhost:8888/time/ and see the same welcome page, even though I don't have an .htaccess file in the root directory.
Here is the problem. I added the following function to the Welcome.php controller class:
public function test()
{
echo 'Test';
}
This should display a page which shows 'test' when I visit http://localhost:8888/time/index.php/test. However, I get a 404 page not found error. Does anyone have any suggestions for understanding and fixing this problem?

Because localhost/index.php/test doesn't refer to the method test in the welcome controller. You would have to go to localhost/index.php/welcome/test or use routes.
They way you are doing it implies there is a controller named Test.php and it is trying to go to the index() function of that controller.

Related

CodeIgniter 4.0 shows me 404 error repeatedly

I wrote the corresponding controller through the CodeIgniter document, but the page always shows me 404. My question is why exactly the same URL can not be displayed, and why this framework can only show me 404 pages. I remember that ThinkPHP has a complete running link for error reporting, and I can't see the problem with only one 404.
this is my url
http://localhost/index.php/demo/test
this is my Demo.php code
`<?php
use CodeIgniter\Controller;
class Demo extends Controller
{
public function test()
{
echo 1;
}
}`
Demo. PHP files must be in the controller folder and there are no other directories, but CI reports 404 errors to me
Its because they dramatically changed routes, you need to define in \Config\Routes.php and check their wiki as I am in process of refactoring my scripts.
Add a route with this
$routes->get('pineapple','Demo::test');
ensure your server has mod_rewrite enabled and that you have .htacces file.
make sure that your base_url in app/Config/App.php is set with an ending slash on the url /

Codeigniter Custom Controller Receiving 404

So I copied the controller file Welcome.php and named it home.php.
I changed the class name from Welcome to Home.
When I go to view it in http://daytodata.net/ci/index.php/home I get a 404?
Did you try accessing your method using /home/index/ ?
Also you should consider take advantage from routing system:
https://www.codeigniter.com/userguide3/general/routing.html

404 href error PHP script

Im new to laravel, but im trying to integrate an existing php script that I have into the laravel app. I understand everything happens in a MVC based architecture. However,im trying to link this page into the header page whose path is application/view/templates/header.php.
For example, there is a controller present in application/controller/LoginController.php and that has a function called public function index() and the way which it is called from headertemplate is:
<li <?php if (View::checkForActiveControllerAndAction($filename, "login/register")) { echo ' class="active" '; } ?> >
Register
</li>
<li>
Administrator Login
</li>
As you can see when i try to call a script which is in the root directory, called admin.php it gives me a 404 - Page not found.
Im really struggling I hope someone can help me figure out the problem. A 404 error is never fun as it is only a tiny error.
If you really want to run a basic PHP script then you can always chuck it in the public directory or try routing it from somewhere else. You're using it as a login script for admins so I would highly suggest just reprogramming it to be a part of your laravel site. Totally up to you though, this may not be the best answer but it will work.
I would suggest do it step by step
Route
In your /app/Http/routes.php
Route::get('/login/register', 'LoginController#index');
Controller
Let make sure you create a LoginController.php in /app/Http/Controllers/
Function
In your /app/Http/Controllers/LoginController.php , create a function call index to return a view.
public function index(){
return view('templates.header); // <-------- /templates/header.blade.php
}
View
inside your /resources/views/templates create header.blade.php
Place all the HTML code needed in it
Test
go to http://localhost/login/register
should load what you place in side your header.blade.php
You shouldn't get 404 anymore.

codeigniter issue with loading view from controller

I am new to codeigniter and really interested in trying it out. I followed the guide but ran into a problem. It seems like I am unable to load my first page properly.
I have inside the view folder another folder called general and inside it index.php.
in controller folder, I have sub-folder with general and inside it is Default controller.
I have the following route and yet the page showing is blank
$route['default_controller'] = "general/default";
$route['404_override'] = '';
When I visit the link, I type this in browser:
http://localhost:8888/treventa/
and the screen is blank. Am I doing something wrong? Sorry if this is too simple but a person got to learn from his mistake :)
Try with me step by step:
Firstly: the Controller:
(main.php) File content
if (!defined('BASEPATH'))exit('No direct script access allowed');
class Main extends CI_Controller {
public function index() {
$this->load->view('general/welcome');
}
}
Secondly: The view:
(welcome.php) File content
You can put anything you want
<h1> Hello, I'm the view file </h1>
Finaly: The routes:
(routes.php) File content
$route['default_controller'] = "general/main";
Now call the script like this http://localhost/codeIgniter/, that's where codeIgniter is the script folder name.
I think everything now is clear.
CI trying to use method default() of general controller. If You want to use folders for controllers, make sure You specify method, so try $route['default_controller'] = "general/default/index";
And one more thing: this method (default_controller) will be used when You trying reach Your root http://localhost:8888/, if You want to route request from http://localhost:8888/treventa/ to default controller, You need to add route-rule to /config/routes.php something like $route['treventa'] = "general/main/index";

404 Error after Renaming Controller, View & Default Controller

I'm getting a 404 Page Not Found error in CodeIgniter\WAMP after doing the following:
renamed a controller (from welcome.php to search.php)
renamed the view to load from search.php as *search_page* (see below)
renamed the related view (from *welcome_message.php* to *search_page.php*)
renamed the default controller in config\routes.php to search
restarted WAMP
search.php
public function index()
{
$this->load->view('search_page');
}
config\routes.php
$route['default_controller'] = "search";
Where did I go wrong?
i'm not a codeigniter programmer, but you should make the class Search -> class Search extends CI_Controller, no? found it on this link -> http://ellislab.com/codeigniter/user-guide/general/controllers.html
i think it's the same in every framework, cakephp, codeigniter, zend etc.

Categories