i installed fresh cakephp. its app controller working fine. but when i write my controller and its view but this result in page not found. My code is given below
class PostsController extends Controller {
public $helpers = array('Html', 'Form');
public function index() {
$this->set('posts', $this->Post->find('all'));
}
}
and create folder named Posts in view folder and over there create index.ctp file as well. but its result in page not found. Please help what may be mistake by me or is there any need to configuration. Thanks
Your controller should be named PostsController.php (ie plural)
Just spotted it, you need to extend AppController in CakePHP 2.x, not Controller: ie:
class PostsController extends AppController {
there might problem apache rewrite module. if you are using WAMP, just put on your rewrite module.
Related
I am trying to add controller view in my existing project that consider model view controller structure in php with laravel.
class CashFlowdataController extends Controller {
public function index() {
return view('CashFlowdata::create');
}
}
When I implement this, it shows me error for,
InvalidArgumentException
No hint path defined for [CashFlowdata].
I have added file in route.php and web.php as added other controller data. Only for this one it shows message like this.
you code is wrong you should to something like this
class CashFlowdataController extends Controller {
public function index() {
return view('CashFlowdata.create');
}
}
here CashFlowdata.create
its means in laravel
folder structure should be
view>CashFlowdata>create.blade.php
laravel view() function is a helper to load view file
ref link https://laravel.com/docs/8.x/helpers#method-view
I had the same issue in nwidart/laravel-modules due to module.json file was miss place.
I move the file to the root of module now working fine.
Hi I followed this tutorial: https://book.cakephp.org/3/en/tutorials-and-examples/blog/part-two.html and having problem when tried to access the links: localhost/myprojectname/articles/index and localhost/myprojectname/articles/view/1
This is the screenshot:
Error:Missing Controller
I am using XAMPP and Chrome browser. The article model, articles controller and article view are created as written in the tutorial. But when I was trying to access the link at localhost/myprojectname/articles/index, there is missing controller error as shown in the screenshot above.
However, after insert <?php in the top of the articles controller and article model file, still showing same missing controller error as this screenshot: Error: Missing Controller 2
Copy and paste this to your AppController:
<?php
namespace App\Controller;
class ArticlesController extends AppController
{
public function index()
{
$this->set('articles', $this->Articles->find('all'));
}
public function view($id = null)
{
$article = $this->Articles->get($id);
$this->set(compact('article'));
}
}
My Master controller located in "admin" folder. View image
here
namespace App\Controllers\admin;
use CodeIgniter\Controller;
class Master extends Controller
{
function __construct(){
helper('url');
}
public function index()
{
$data["content"]="view_home";
echo view('template/template', $data);
}
}
In my Routes.php i added this
$routes->get('admin/master','Master::index',['namespace','App\Controllers\admin']);
when i access the page in the browser i get this error
404 - File Not Found
Controller or its method is not found: {0}::{1}
What am i missing?
My silly mistake when setting up the route. I've put a "," instead of "=>". See the correct route below.
$routes->get('admin/master','Master::index',['namespace' => 'App\Controllers\admin']);
I'm facing one weird problem with my Codeigniter project.
I have two model files in the following paths:
models/public/Dish_model.php
models/admin/Dish_model.php
For front-end and back-end models respectively.
In the controller which is in the following path:
controllers/admin/Dish.php
I'm trying to load the admin area model file using:
$this->load->model('admin/dish_model');
But it is loading the public model file.
Even if I comment this line out the public model file still gets loaded.
This all happened suddenly it was working fine before and I haven't changed any of the mentioned files recently.
Any help?
In case anyone else encounter the same issue.
In my case and after carefully following the execution path of the controller I found that the other model was being loaded by a library in the autoload list.
Removing that library from the autoload array fixed the problem.
to call/load a model from its subdirectory or subfolder.
models/public/Dish_model.php
let's say in Dish_model
class Dish_model extends CI_Model{
public function __construct(){
parent::__construct();
}
public function the_method(){
return 'return value';
}
}
models it's a native ci model directory and public it's a subdirectory. so to load the Dish_model do this on controller
$this->load->model('public/Dish_model','DModel');
the DModel it is like an alias.
so to call the model from the controller is
echo $this->DModel->the_method();
and it will return return value
hope its help.
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.