Welcome Guest, Not a member yet? Register   Sign In
Controller or its method is not found: \App\Controllers\Tasks::index
#1
Question 
(This post was last modified: 07-11-2022, 08:27 AM by Ahmed Haroon.)

simply unzipped CodeIgniter ver 4.1.9 in d:\xampp\htdocs folder and rename it to taskapp.
in .env file :

CI_ENVIRONMENT = development
app.baseURL = 'http://localhost:8088/taskapp/public'

in Routes.php i set :
$routes->setAutoRoute(true);

in browser i can run successfully: http://localhost:8088/taskapp/public
created a folder in Views and a file under this folder index.php
in Controllers modified Home.php to return that view file successfully.
return view('Home/index');

all 3 url's are working fine, showing the same page:
http://localhost:8088/taskapp/public
http://localhost:8088/taskapp/public/home
http://localhost:8088/taskapp/public/home/index

copied that Home.php in Controllers and rename it to Tasks.php which contents are as below:


PHP Code:
<?php

namespace App\Controllers;

class 
Tasks extends BaseController
{
    public function index()
    {
        return view('Tasks/index');
    }


created a folder in Views named Tasks and under this folder created a file index.php which contents i copied from index.php as below:

PHP Code:
<!DOCTYPE html>
<
html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>Tasks</title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="">
    </head>
    <body>
        <h2>Welcome Tasks!</h2>
    </body>
</
html

in browser trying to access below but it shows error:
http://localhost:8088/taskapp/public/tasks

404 - File Not Found
Controller or its method is not found: \App\Controllers\Tasks::index

what i missed or doing wrong here? please guide
regards
Newbie here in CodeIgniter World !! Please appologize if any nonsense from me.  
environment: Windows 10, XAMPP 3.3.0, VS Code, SQLyog Community Ed. 
Reply
#2

Its a very basic (starting point) static pages question, hope soon will get the answer.
both files are Almost same in App\Controllers\Home.php and Tasks.php
both files are Almost same : a) App\Views\Home\index.php b) App\Views\Tasks\index.php
regards
Newbie here in CodeIgniter World !! Please appologize if any nonsense from me.  
environment: Windows 10, XAMPP 3.3.0, VS Code, SQLyog Community Ed. 
Reply
#3

No, it is a very difficult question. Because your code should work.

What if you use CI 4.2.1?

What if you use `spark serve` command, not Apache?
https://codeigniter4.github.io/CodeIgnit...is-working
Reply
#4

(This post was last modified: 07-12-2022, 12:54 AM by Ahmed Haroon.)

@kenjis 
also used current version using official guide Composer Installation but failed to get it.
will check "spark serve", not yet tested because the controller Home.php is showing the page as expected but Tasks.php not.
will give you feedback.
regards

no, the same error message appears after "php spark serve" and enter in browser
http://localhost:8080/tasks

while http://localhost:8080 is showing home page and this too: http://localhost:8080/home
regards
Newbie here in CodeIgniter World !! Please appologize if any nonsense from me.  
environment: Windows 10, XAMPP 3.3.0, VS Code, SQLyog Community Ed. 
Reply
#5

change the base url to below and you should be able to run the app via spark "php spark serve"

app.baseURL = 'http://task.localhost/'

If you want to use "Xampp" don't use the default location "htdocs", create a new virtual hosting and point that to the app public folder.

virtual host code :
<VirtualHost *:80>
ServerName task.localhost
DocumentRoot "d:\xampp\htdocs\task\public"
<Directory "d:\xampp\htdocs\task\public">
Require all granted
AllowOverride All
</Directory>
</VirtualHost>

restart xampp and you should be able to access "http://task.localhost"
Reply
#6

@chakycool
will check as advised / guide, hope that work.
regards
Newbie here in CodeIgniter World !! Please appologize if any nonsense from me.  
environment: Windows 10, XAMPP 3.3.0, VS Code, SQLyog Community Ed. 
Reply
#7

I cannot reproduce with CI 4.2.1.

I navigate http://localhost:8080/tasks and see "Welcome Tasks!"

See https://github.com/kenjis/ci421-tasks-index
Reply
#8

(07-12-2022, 02:13 AM)kenjis Wrote: I cannot reproduce with CI 4.2.1.

I navigate http://localhost:8080/tasks and see "Welcome Tasks!"

See https://github.com/kenjis/ci421-tasks-index
thanks very much for your passions to help us.
downloaded your project .zip file, extracted in E:\xampp\htdocs and in app folder when run " php spark serve " it showed error as in screenshot: (is anything else i have to done for this?)
[Image: php-spark-error.jpg]
regards
Newbie here in CodeIgniter World !! Please appologize if any nonsense from me.  
environment: Windows 10, XAMPP 3.3.0, VS Code, SQLyog Community Ed. 
Reply
#9

It is app starter installation.
https://codeigniter4.github.io/CodeIgnit...pp-starter

You need to run `composer install` or `composer update`.
Reply
#10

@kenjis 
my feedback to seniors and what i did for juniors like me to have succefully access desired page. 
1) downloaded CI4 manually from official website
2) extracted in folder E:\xampp\htdocs\ci4test\ 
3) copied env file to .env and added  " app.baseURL = 'http://localhost:8088/ci4test/public' "
4) after initial test run, created my Tests as mentioned in starting post here ( App\Controllers\Tasks.php  and App\Views\Tasks\index.php create from Home.php and Home\index.php )
5) test run fail again
6) googled again, now today i found some solutions and its done (very basic, but it was successfully run by instructer Dave Hollingworth in video course  without entries in Routes.php, he only changed $routes->setAutoRoute(false); to true . when i added an entry in Routes.php as $routes->get('/tasks', 'Tasks::index'); and in browser enter http://localhost:8088/ci4test/public/tasks then it is showing what it has to.
is this due to some changes/enhncements/security or something else i failed to understand? please guide us.
regards
Newbie here in CodeIgniter World !! Please appologize if any nonsense from me.  
environment: Windows 10, XAMPP 3.3.0, VS Code, SQLyog Community Ed. 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB