PhpStorm CodeIgniter 404 page not found - codeigniter

I am facing a problem with CodeIgniter framework in PhpStorm.
I have created a controller as home.php with a public function test. And I've created a view page as mytest.
In browser when I type http://localhost/mvc/index.php/home/test/
the page is not loading it shows
"404 page not found".
What might be the problem?
Using XAMPP and CodeIgniter 2.1.0

Check your class name,class name should be same as file name,which version of ci are you using?

Controller name : Home.php
Method / Function : test()
View : mytest.php
class Home extends CI_Controller
{
public function test()
{
$this->load->view('mytest');
}
}

Related

How to write route for breadcrumb in laravel?

Route::get('/usersearch', 'UsersController#usersearch');// for this url write breadcrumb
Route::Resource('user','UsersController');
how can i write breadcrumb route ? I want display on index.blade.php which is located in user folder
Laravel resource routing assigns the typical CRUD routes to a controller with a single line of code. See Official Documentation
In your case, route :
Route::resource('user','UsersController');
UsersController :
public function index()
{
return view('user.index'); // views/user/index.blade.php
}
Install Laravel Breadcrumbs
github.com/davejamesmiller/laravel-breadcrumbs
Run this at the command line:
composer require davejamesmiller/laravel-breadcrumbs:5.x

How to work with subdirectory controllers in CodeIgniter 4?

I need help with using sub directory controllers in CodeIgniter 4.
I just can't make it work for some reason.
This is the URL for example: www.example.com/admin/dashboard
In the controllers folder, I created a folder named Admin, and a file named Dashboard.php.
I used this code in Dashboard.php:
namespace App\Controllers;
class Dashboard extends BaseController
{
public function index()
{
}
}
I tried changing the class name to AdminDashboard, Admin_Dashboard, pretty much every logical name but every time I get a 404 error, saying:
Controller or its method is not found:
App\Controllers\Admin\Dashboard::index
I know the file itself gets loaded successfully, but I think I don't declare the classname correctly and it keeps throwing me those 404 errors.
The documentation of CI4 isn't providing any information about what the classname should be called unfortunately...
UPDATE #1
I managed to make it work by changing few things:
namespace App\Controllers\Admin;
use CodeIgniter\Controller;
class Dashboard extends Controller
{
public function index()
{
}
}
But now it won't extend the BaseController which has some core functions that I built for my app.
Any ideas to how to make it extend BaseController?
I must admit that I don't have much knowledge about namespacing yet, so that might be the reason for my mistakes.
As I imagined, the problem was that I didn't learn about namespacing.
I needed to point the use line at the BaseController location.
namespace App\Controllers\Admin;
use App\Controllers\BaseController;
class Dashboard extends BaseController
{
public function index()
{
}
}
Now www.example.com/admin/dashboard/ goes directly to that index function, as intended.
php spark make:controller /Subfolder/ControllerName
$routes->add('/(.+?)_(.+?)/(.+?)$', 'subdir\\\\$1_$2::$3');
$routes->add('/(.+?)_(.+?)$', 'subdir\\\\$1_$2::index');
I was able to map with this setting.
The route mapping could be as simple as:
$routes->group('admin', static function ($routes) {
$routes->get('dashboard', 'Admin\Dashboard::index');
});

Yii2 redirect 404 Page not found

I have custom page in view/stock/three.php ( which I make) , I render it in StockController , and I try to open it from view/site/shop.php with
<div class="pager ">3</div>
but I get Not Found (#404) Page not found. . ( I didnt forget to set "use Url")
I try also to redirect it from SiteController with :
public function actionThree() {
return $this->redirect(['/stock/three']);
}
but also didnt work and still got Error code 404
maybe you don't have a 'three.php' file inside views/stock folder or that forward slash ('/') before 'stock'.
Try this
public function actionThree() {
return $this->redirect(['stock/three']);
}
I make new Model and new Controller for pages where I write :
public function actionThree() {
return $this->render('three');
}
and then
<div class="pager ">3</div>
work

Laravel views do not output anything

I'm new to PHP Laravel framework. I'm studying it and playing with simple examples of code. My problem is that my views do not output anything - a blank white screen appears when I try to reach controller methods, for example, localhost/my-application/cms/action1
My routes file:
Route::controller('cms', 'CmsController');
My controller:
class CmsController extends BaseController {
public function getIndex()
{
View::make('cms.index');
}
public function getAction1()
{
View::make('cms.action1');
}
public function getAction2()
{
View::make('cms.action2');
}
}
My views are located in views/cms. They are very simple, for example:
<h1>Action1</h1>
<?php echo 'this is Action1'; ?>
And these views do not output anything, just simple blank white page appears. I tried to:
1) rename views files, and Laravel threw exception - "view not found", or so.
2) move view::make() methods to Routes file - the views were displayed then.
So where is the problem?
The bootstrap index.php file in laravel is inside the public folder.
So unless you've created a vhost for your application, you have to access it like
localhost/my-application/public/cms/action1
EDIT
Forget it. The problem is that you do not return the view::make from each function.
return View::make('cms.index');

CodeIgniter Undefined Variable while trying to create subview

Hi I am new to CodeIgniter and am taking a tutorial. I ran into an error
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: subview
Filename: admin/_layout_modal.php
Line Number: 7
An Error Was Encountered
Unable to load the requested file: .php
I followed the tutorial to the tee and I cant seem to find out where I am going wrong.
here is the controller
<?php
class User extends Admin_Controller {
public function __construct() {
parent::__construct();
}
public function login() {
$this->data['subview'] = 'admin/user/login';
$this->load->view('admin/_layout_modal', $this->data);
}
}
and the view
<?php $this->load->view($subview); ?>
Please help...
If you gave script from your .php file not tutorial then everything is ok.
You are probably typing the wrong url in when you try to access the page. Make sure you are loading "admin/user/login" instead of "admin/dashboard/modal".
If you are following tutplus tutorial- building cms with codeigniter, First watch two episodes, Managing User Part 1 and Managing User Part 2 and then Start building, Your question will be answered on Part 2.... the dashboard has to declare the subview variable and
CREATE THAT admin/dashboard/index.php file in views
class Dashboard extends Admin_Controller{
public function __construct(){
parent::__construct();
}
public function index(){
$this->data['subview'] = 'admin/dashboard/index';
$this->load->view('admin/_layout_main',$this->data);
}
public function Modal(){
$this->load->view('admin/_layout_modal',$this->data);
}
}
don't need to pass data to $this. Just pass the data to
$data['variable_name']=data;
pass this $data variable to view through load class.

Resources