I am using CakePHP for the first time and I have a trouble with requests.
I have for example this simple controller:
class TestController extends AppController
{
public function index() {
}
public function edit() {
}
public function view() {
}
}
Index is rendering right but when I call /test/edit or /test/view I am redirected (302) to the root of my webpage. Views for each action are created.
It's the same for any other controller in my app.
I cannot figure out why. Do you have any ideas, suggestion what should I check?
Thi was the problem $this->Auth->allow(['edit']); now it is working.
Related
Simple controller so far:
class Login extends CI_Controller {
public function index()
{
echo 'Hello';
}
}
Route:
$route['(:any)'] = 'login/index';
From my understanding anything typed into the address bar gets routed to the Login controller using the index method? Am I understanding this correctly?
Result: Unable to determine what should be displayed. A default route has not been specified in the routing file.
Editing this post entirely as I realize that I did a poor job of explaining things as they are, and to reflect a few changes already implemented.
The issue: I have an app that has a normal front end, which works perfectly when accessed via app\public. I've added a backend and wish to use a different master layout. I have named the backend Crud. I created Crud\UserController and that has the following:
public function __construct()
{ $this->middleware('auth'); }
public function getIndex() {
return view('crud'); }
In my routes.php file I have the following:
Route::controller('crud', 'Crud\UserController');
I've tried placing that route inside and outside of the middleware group. Neither workds. I do have a file, crud.blade.php, that exists inside resources\views.
The issue is a 404 from apache every time I try to access app/public/crud. Specifically, this error:
The requested URL /app/public/crud was not found on this server.
I'm at a loss as to why the server is unable to find the route to crud.blade.php
ETA: The apache access log just shows a normal 404 when I attempt to access this page. The apache error log shows no errors.
The view() is suppose to point to a view file, that is something like example.blade.php which should contain the content you want displayed when the localhost:app/crud is visited. Then you can do view('example') without the .blade.php.
From your code, change
class UserController extends Controller{
//Route::controller('crud', 'Crud\UserController');
public function __construct()
{
$this->middleware('auth');
}
public function getIndex() {
return view('/');
}
}
to
class UserController extends Controller{
//Route::controller('crud', 'Crud\UserController');
public function __construct()
{
$this->middleware('auth');
}
public function getIndex() {
return view('crud'); // crud being your view file
}
}
I think you're mixing concepts. Trying to get here will always throw an error:
localhost://app/crud
To enter your app, just try to access:
http://localhost
appending a route you registered in your routes.php file. In your example, It'd be:
http://localhost/crud
If you register
Route::get('/crud', 'Crud\UserController#index')
Then you need an Index method inside UserController, which should return a view (in your example)
class UserController extends Controller{
public function __construct()
{
$this->middleware('auth');
}
public function index()
{
return view('crud');
}
}
P.S: about Implicit controllers, you have the docs here.
I have a controller class and inside i have a contructor, that loads a specific model. I've checked the model code, theres not anything wrong in it. However the controller script shows a white screen error if that model is loaded.
Heres the controller code:
class Home extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->model('Adder');
}
public function send_feedback()
{
$this->Adder->addTo('feedback');
}
}
I have main controller.
Controller Folder: main.php
the usual coding is you will call everything from main controller.
class Main extends CI_Controller{
public function index(){
//line of codes
}
public function login(){
//line of codes
}
public function register(){
//line of codes
}
}
So instead of doing this, I'm thinking to make login and register as sub controller and call them from the main controller but I don't know how to call them.
Controller folder: main.php, login.php, register.php
Please paste some line of code and if you can explain it as well.
Hi first of all I'm using cakePHP 2.3.x
I'm having problem excluding my view pages from authentication. For example I have my static home page in Pages/home.ctp
In my AppController and PagesController I putted:
public function beforeFilter() {
$this->Auth->allow('home');
//$this->Auth->deny('add','edit','delete','index');
}
Yet it still requires me to log in.
I also putted in my PagesController
public function home(){
}
But still no luck.
Any help will be appriciated
please try with this in pages controller
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow("*");
}
OR try with $this->Auth->allow("display");
Instead of using PagesController I created a copy of it and name it with another name. I just deleted the display() function and put all other action there, and created the view and it runs good. I guest you can't just put a lot in PagesController.