404 href error PHP script - php

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.

Related

Codeigniter controller method 404 error

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.

Laravel 5 - Route Controller Error

I am having troubles with connecting one of my routes to its associate controller function.
Routes file
Route::get('/transaction/export','TransactionController#exporter');
Controller and Function
class TransactionController extends Controller
{
public function exporter(){
dd("works");//-->Not seen :(
return view('admin.transactionExport');
}
}
Link in view
Export
When clicking on the link, the address bar in the browser shows the expected url '/transaction/export', but unfortunately it shows me a blank page. It is as though the function in the Routes file does not link to the proper controller. I have over 30 successful links in this site, and have no idea why this is failing on me right now.
Would appreciate the help. Please inform me if more information is needed to solve this.
Change your route to match the controller:
Route::get('/transaction/exporter', 'TransactionController#exporter');
Your previous route wasn't matching 'exporter'.

How to add a new page to the admin view of laravel framework

I have a website in laravel framework and I am trying to add a simple new static page to the admin panel. I have done the following three steps:
Add a template to the views:
app/views/admin/MessageToAll.blade.php
Add the make view code in the controller.
public function MessageToAll(){
return View::make('admin.MessageToAll');
}
Added a route in app/routes.php
Route::get('/admin/MessageToAll',array('as'=>'MessageToAll','uses'=>'AdminController#MessageToAll'));
But when I go to to domain.com/admin/MessageToAll
it gives me a 404 page not found error. Does anyone know what have I missed as I think I have completed all steps for adding this view.
Just put your new route before the /admin/ route (to test it, you want to temporarily make it the very first route in routes.php). The problem is /admin/ or some other similar route executed before your new route.
Also, if you need to just execute static view, you can use something like this (works without using a controller):
Route::get('/admin/MessageToAll', function (){
return View::make('admin.MessageToAll');
});
in routes add:
Route::get('/admin/MessageToAll','yourController#yourMethod');

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";

CodeIgniter: show a view by typing its url

A newbie here: sorry if the question is too simple, been looking in tutorials but I don't seem to look properly.
I have the
$route['default_controller'] = "mainpage";
in routes.php working properly, and now I just want to view one of the php pages in views folder by typing its url:
http://myserver/folder/thepageIwantToSee
I get a 404 Not Found error. Do I have to use a controller? I just want to see it first before any linking, is there a way to do it?
Thanks a lot!
class yourcontroller extends CI_Controller {
function pageiwanttosee()
{
code
code
$this->load->view('the_view_page', $data);
}
}
Yes, you can write a controller that displays the view specified.
http://myserver/showfile/folder/thepageIwantToSee , where showfile is your controller.
Don't forget to set some security check or disable this on production site.

Categories