Fatal Error in CodeIgniter - codeigniter

I am facing a Fatal error:
Class 'Controller' not found in D:\wamp\www\CodeIgniter\application\controllers\blog.php on line 3
I am typing write and i watched so many tutorials they are also typing beginning code like this i tried a lot to find out but got no reason

Are you using CI 2.O? Did you by any chance write the following in your controller:
class Blog extends Controller { ... }
If you're using CI 2.0, you should use the following:
class Blog extends CI_Controller { ... }
You might have been watching outdated tutorials for CI 1.7.
Reference: http://codeigniter.com/user_guide/general/controllers.html
Make sure to follow the userguide along with whatever tutorials you're following; there's some changes in 2.0 which you should be aware of. You can still follow these tutorials though, just keep your eyes open and compare with the userguide.

What version are you using? if you're using the latest (2.0.2), make sure you use CI_Controller when extending your controller.
Seeing you named the file blog.php, your controller should be looking like this
Class Blog extends CI_Controller {
function index()
{
// your code...
}
}

Related

PHPUnit Error: Call to undefined method Tests\Unit\ExampleTest::visit()

This is the test case I've written and when i try to run it with this command vendor/bin/phpunit on linux it gives me the error "Call to undefined method Tests\Unit\ExampleTest::visit()"
namespace Tests\Unit;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*
* #return void
*/
public function testBasicTest()
{
$this->visit('/Login')
->type('KP123#gmail.com','email')
->type('123456','password')
->press('Login')
->seePageIs('/home')
->see('Katy Perry');
}
}
I've tried running composer update and it still could not work. Had Anyone experienced this issue before?
The visit() method looks like it's part of the SeleniumTestCase. So my guess is you either extend from the wrong base class. I assume it should look something like this:
class ExampleTest extends \PHPUnit_Extensions_Selenium2TestCase
{
// your test method
}
edit: I just noticed the Laravel tag, so it's probably more something like Illuminate\Foundation\Testing\TestCase. If this gives you errors that it can't find the class you have to set the bootstrap file in your phpunit.xml to the vendor/autoload.php or another appropriate bootstrap file where the file is registered in the autoloader.
I might have come in late onto this question but here is my 2 cents. I have been trying to use the same methods with my test case which led to a dismal failure.
I the realised that I could actually make use of the TestResponse class which is found on the Foundation namespace that wraps many methods around the response object.
$this->get('/url/to/visit'); //Then you can make your assertions on the returned response.
In my case I had authentication turned on for the application therefore it always complained about the header view where we display the username of the currently logged in user. If you run into that situation then use the Auth Facade like shown below:
\Auth::loginUsingId(1);
You should now be able to assert that your response has some text in it. Hope this helps. By the way I am on Laravel 5.4
If you are using new version of Laravel you must use Laravel Dusk to use similar methods to $this->visit or see. It was excluded from Laravel around version 6.
Instead you can use, but it has limited options:
$this->get('/Login')
composer require laravel/browser-kit-testing --dev
Try this
if you are using > Laravel 8 try :
$this->get('/Login')
instead of visit function, and assertSeeText instead of see

I am using REST_controller in HMVC (CI3.1).

It is working correctly with MX_Controller.It is throwing error as 'Fatal error: Class 'CI_Template' not found' when using REST_Controller.Any help will be appreciated.
I'm not entirely familiar with the inner workings of Codeigniter's third party add-on HMVC. However, the code base that I inherited is using it.
I ran in to the same issue when installing restserver, https://github.com/chriskacerguis/codeigniter-restserver which is what I assume you were also doing.
REST_Controller.php has this
abstract class REST_Controller extends \CI_Controller {
While I have never been able to get CI_Controller to work with this codebase, I now believe it is because of this HMVC. For those not familiar, HMVC is Hierarchical Model View Controller.
Module Controllers can be used as normal Controllers or HMVC
Controllers and they can be used as widgets to help you build view
partials.
https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc
I did get REST_Controller.php working by changing the line to
abstract class REST_Controller extends \MX_Controller { // \CI_Controller {

Why wont my Codeigniter model load on Lamp?

My model is:
/application/models/tester.php
The code inside is:
class Tester extends CI_Model
{
function __construct()
{
parent::__construct();
$this->load->database();
}
}
And here's the usage:
class Hauth extends CI_Controller
{
public function index()
{
$this->load->view('hauth/home');
}
public function login($provider)
{
// Load models
$this->load->model('Tester');
// Load helpers
$this->load->helper('url');
log_message('debug', "controllers.HAuth.login($provider) called");
It works perfectly on my local WAMP server but I get this error on the LAMP production envrionment:
An Error Was Encountered
Unable to locate the model you have specified: Tester
I've looked at a dozen StackOverflow questions that appear to be similar but I've tried all of the solutions posted. As far as I can tell, I've followed the CI manual to the letter. I figured that perhaps file names were an issue WAMP vs LAMP so I confirmed the case of the file names via FTP. Thought it might be a naming conflict, so I renamed them "tester". Again, works perfect on local, but not on live.
I found the problem. Turns out I accidentally used a zip of Codeigniter 3.0-dev. When I moved my application files over to the latest stable version, everything instantly worked.

Laravel Controller not working

I'm very new to the Laravel framework and am trying to load a simple controller in my browser to slowly get the hang of things.
I have a file that's titled users.php inside of the the laravel/app/controllers/ folder and it looks like this:
class UsersController extends BaseController
{
public $restful = true;
public function action_index()
{
echo 'hi';
}
}
In the routes.php file, I have
Route::get('users', 'UsersController#index');
But, when I go to
http://localhost:8888/laravel/public/users
I'm greeted with a message that says "ReflectionException
Class UsersController does not exist"
I'm not sure if this is because I didn't install the mcrypt extension of PHP. But, when I checked the php.ini file on MAMP, it said that it was enabled. Upon entering
which PHP
in my terminal, it said /usr/bin/php. So, it might not be using the correct version of PHP.
I'm not entirely sure if this is a routes problem or if it's stemming from an absence of a vital PHP extension.
Thanks a bunch!
You need to use the Route::controller method to reference your Controller:
Route::controller('test', 'TestController');
...and rename your file (as Cryode mentions ) to be TestController.php.
Note - if you want to use the filename as test.php, then you will need to use composer to update the autoload settings.
Finally, the format of names for Controller methods changed in Laravel 4, try renaming the method
public function action_index() {}
to be
public function getIndex() {}
the get represents a HTTP GET request... the same applies for post (HTTP POST) and any (GET or POST.. )
I'm not familiar with that part of Laravel's source, so I'm not entirely certain that this is the issue, but your controller file name should match the controller class name, including capitalization.
So users.php should be UsersController.php. Now, when I do this myself on purpose, I get a "No such file or directory" error on an include() call, so that's why I'm not certain that's the sole cause of your problem. But it may be a start.

google calendar with codeigniter

I'm trying to integrate Google Calendar in my php application (I use CodeIgniter for this).
I have a problem with my controller calendar.php.
<?php
session_start();
Class Calendar extends Controller {
function Calendar(){
echo 'start';
parent::Controller();
echo 'okkkkkkkk';
require_once '/home/me/framework/ZendGdata/library/Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_AuthSub');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Calendar');
}
but there is a problem with parent::Controller() because 'okkkkkk' is not printed.
Could anyone help me please?
Change
parent::Controller();
to
parent::__construct();
parent::Controller() doesn't work in CI because as of CI 2.1.2, the constructors are declared using PHP's __construct() method.
As a sidenote, it seems you are using an older version of CI. CI 2.o onwards, the base controller class is called CI_Controller as opposed to just Controller. You should look into updating your project by replacing the system folder.
You can find the full working code in this following link https://github.com/omerkamcili/ci_google_calendar_api.
After down loading the code create your service account, OAuth client Id's in the following link http://console.developers.google.com.
Then replace the client_id,client_secret,redirect_uri's in your project file in the following path -> /project_folder/application/config/client_secret_846685841138-t0a5b9d2i655e7km54md8j440jcg5rr5.apps.googleusercontent.com.json file
Finally download and replace the google-api-php-client in the following file path /project_folder/application/third_party/google-api-php-client

Resources