CakePHP 3.8 Blog Tutorial Error: Mising Controller - php

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'));
}
}

Related

Conroller name in url in codeigniter 4 is not working

enter image description hereWhen I use this
Localhost/CI4/public
OR
Localhost/CI4/public/index.php
It loads and shows default page with default controller, but when I use
Localhost/CI4/public/index.php/Home
OR
Localhost/CI4/public/index.php/Home/index
It gives *`404 error File Not Found - Controller or its method is not found
1
Routes. Php file
2
Assume my controller name is ContactController and the method is index. And I'm accessing it with the URL contact
In config/route.php
$routes->get('contact', 'ContactController::index');
In Controller
namespace App\Controllers;
class ContactController extends BaseController
{
public function index(): void
{
echo "call me";
}
}
To access this just use
http://localhost/contact
Nothing to do with public or index.php

How can i access my controller located in "folder_name/controller_name" in codeigniter 4?

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']);

Cakephp Error: Class 'CI_Controller' not found Error, how can it be fixed?

I installed Cakephp as part of my tutorial, and I wanted to start a basic page with only hello world.
I written the class in the Hellopagecontroller.php < a file i created:
<?php
class HelloController extends Controller
{
public function index()
{
echo "Hello, CakePHP World";
}
}
?>
An image to illustrate:
An image of the files I
This is the output I have when opening the index page it doesn't show hello, cakephp world rather
Error: Class 'Controller' not found File
/Applications/XAMPP/xamppfiles/htdocs/Test2/src/Controller/HelloController.php
Line: 5
The error I am getting
note: cakePHP version: 3.4.6 - PHP Version:5.6.28
You are missing out to declare the namespace, and you should extends your class from AppController.
If you are new on CakePHP framwork, I highly recommend you check the Bookmarker Tutorial out.
<?php
namespace App\Controller;
class HelloController extends AppController
{
public function index()
{
echo "Hello, CakePHP World";
}
}
?>
Remove all spaces before start of php tag will remove this problem.

Codeigniter Model loading error

I had a working project uploaded to server 2 week before. It was working fine until now. Below is code for model awsmodel.php
class Awsmodel extends MY_Model {
function __construct()
{
}
// some other functions
}
MY_Model again extends to CI_model.
class MY_Model extends CI_Model {
// required functions
}
From controller pages.php I am calling the function like below.
class Pages extends MY_Controller {
public function index()
{
$data = $this->allCommonMenu();
$this->load->model('Awsmodel');
$data['featured'] = $this->Awsmodel->featuredProp();
$this->load->view('home_pz',$data);
}
}
The above code suddenly stooped working today. After some test and tries, I got to know that when I comment below 2 lines from controller function then The page loads.
$this->load->model('Awsmodel');
$data['featured'] = $this->Awsmodel->featuredProp();
I have changed environment variable to 'development' and tested but still no error message shows. In firefox its showing a blank page, where as in chrome it shows 500 server error. The same code was working since 2 weeks. Don't know why its not working now. If anyone can help me out ?
I am using CI version 2.1.4
If you using CI 3.0 please load model like this
class Pages extends MY_Controller {
public function index()
{
$data = $this->allCommonMenu();
$this->load->model('awsmodel'); //as your model filename: awsmodel.php
$data['featured'] = $this->Awsmodel->featuredProp();
//$data['featured'] = $this->awsmodel->featuredProp();// for CI version 2.1.4 –
$this->load->view('home_pz',$data);
}
}

cakephp controller not working; view page not found

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.

Categories