I'm new to FuelPHP and I did a little coding with it! What I did was create a simple controller and created two methods. One for action_index() and the other is action_add().
the code is given below. Views are already in the app\views\ folder.
class Controller_Student extends Controller
{
public function action_index()
{
return Response::forge(View::forge('index'));
}
public function action_add()
{
return Response::forge(View::forge('select'));
}
}
I've set the root to this controller class. When I run the application the index works fine and loads the directed view. But when I give the following URL
http://localhost/project/public/add/
the method doesn't get called! A 404 error is give saying
You can see this page because the URL you are accessing cannot be found.
What Am I doing wrong here. I've gone through every documentation, tutorial I find but I shouldn't get this type of an error. Please help me.
Below is the routing file code :
return array(
'_root_' => 'student', // The default route
'_404_' => 'welcome/404', // The main 404 route
);
You've set the root to student controller, but that doesn't mean all traffic goes through that controller. Try visiting:
http://localhost/project/public/student/add/
Related
I've been researching up on how to add views and I'm stumped. I want to add a view and all I get are 404 errors. All the examples I see on the web are just to add a default controller. I have a default controller, now I want to add a new page passed an ID in the URL.
This is the controller xyz.php:
class Xyz extends CI_Controller {
public function index() {
date_default_timezone_set('UTC');
$this->load->model('xyz_model');
$this->load->view('xyz_main_view');
}
public function activity() {
date_default_timezone_set('UTC');
$this->load->model('xyz_model');
$this->load->view('xyz_activity_view');
}
}
Model is xyz_model.php, and views are xyz_main_view.php and xyz_activity_view.php.
This is routes.php:
$route['default_controller'] = 'xyz'; // works okay
// $route['xyz'] = 'xyz/activity'; // 404
// $route['activity'] = 'xyz/activity'; // 404
// $route['xyz/activity'] = 'xyz/activity'; // 404
// ... many, many other different approaches
I'm able to use http://localhost, but I'd like to use the following:
// map to main view
http://localhost/index
http://localhost/xyz
http://localhost/xyz/index
// map to activity view
http://localhost/activity
http://localhost/xyz/activity
My understanding is that some of the URLs for the main view should work automatically, not seeing it. Just http://localhost.
I haven't even touched how to get an ID from the URL for the activity page. Just want to get over this first hurdle.
Keep this code in routes
$route['default_controller'] = 'xyz';
Then Try this URL to execute "activity()" function in xyz controller.
http://localhost/[YOUR PROJECT FOLDER NAME]/index.php/xyz/activity
To Pass Parameters such as id's you can use this url.
http://localhost/[YOUR PROJECT FOLDER NAME]/index.php/xyz/activity/[ID]
For more information please check codeigniter routing library. It is really easy to understand.
https://www.codeigniter.com/user_guide/general/routing.html
I am having issues getting the page to render when using a parameter in a create controller. My show controller works but my create controller doesn't. The error thrown is a 404.
Sorry, the page you are looking for could not be found.
The URL is:
http://myapp.test/country/us/state/create
My controller looks like:
// Show
public function show(Country $country, State $state){
return view('state.show', compact('state'));
}
// Create
public function create(Country $country) {
return view('state.create', compact('country'));
}
My route looks like:
Route::get('country/{country}/state/{state}', 'StateController#show');
Route::get('country/{country}/state/create', 'StateController#create');
You need to flip your routes around to be
Route::get('country/{country}/state/create', 'StateController#create');
Route::get('country/{country}/state/{state}', 'StateController#show');
Laravel processes routes in the order that they are defined, so in your current code Laravel was seeing create as a state.
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'.
just started doing some symfony. The root URL i.e. /, works fine and the index/home page is returned well with all the contents. However, I just added a new route i.e. /contact, with it's required controller. When I try to get theis new contact page on a browser, I just get an empty page yet it returns a 200 response code, meaning the request was successful. Quite confusing for me. What could be the problem? Not much code for now since I got no logic but here's my controller:
class ContactController extends Controller
{
/**
* #Route("/contact")
* #Template()
*/
public function contactAction()
{
return array(
// ...
); }
}
If you load the page from app_dev.php, for example http://yourdomain.net/app_dev.php/contact, in log you can check which controller is called, and then you can debug from there the response.
Okay, so I've just gotten around to checking out Laravel 4.1, I've hit a problem and I don't understand why? The problem is that I get this message on the screen "Whoops, looks like something went wrong." but I haven't really done anything. I've created a view, a controller and added a route and this is what is in these files
VIEW
<h1>Author's home page</h1>
CONTROLLER
class AuthorsController extends BaseController {
public $restful = true;
public function getIndex () {
return View::make('authors.index'); //authors.index because it's in the authors folder within the views folder
}
}
and ROUTE
Route::get('authors', 'AuthorsController#getIndex');
So logic dictates that when I go to the authors URL it should load the getIndex function within the AurhorsController page and show the index.blade.php file which is in views > authors.
If so then I have no idea why this is not working! any help would be appreciated. Thanks in advance.
EDIT 1
This is the actual error
throw new NotFoundHttpException();
EDIT 2
You should remove public $restful = true; but it's not a problem for NotFoundHttpException
// Path: app/controllers/AuthorsController.php
class AuthorsController extends BaseController {
// public $restful = true;
public function getIndex () {
return View::make('authors.index');
}
}
According to your route given below:
Route::get('authors', 'AuthorsController#getIndex');
It should work if you make a GET request, make sure you made the request from browser's address bar and url was like yourdomain.dev/authors or http://localhost/yourapp/authors. Also you may run following command from command prompt/terminal (within your project directory):
composer dump-autoload
Looks like Laravel's trying to access the public folder and fails, because there's no file named authors in that folder, and also no route named public/authors. You'll want to go to http://localhost:8081/branch/authors instead, assuming that your installation resides in http://localhost:8081/branch.