John Davidson

php - Debug CController class in Yii1 app with Xdebug

0 comments
Message:


I have a Yii1 application and I am trying to debug the application with Xdebug.


The part that I want to debug is a controller action:


<?php

namespace Scrape\controllers;

use Google\AdsApi\AdWords\AdWordsServices;
use Google\AdsApi\AdWords\AdWordsSessionBuilder;
use Google\AdsApi\AdWords\v201809\cm\CampaignService;
use Google\AdsApi\AdWords\v201809\cm\OrderBy;
use Google\AdsApi\AdWords\v201809\cm\Paging;
use Google\AdsApi\AdWords\v201809\cm\Selector;
use Google\AdsApi\Common\OAuth2TokenBuilder;
use GuzzleHttp\Client;
use Scrape\domain\creator\IgnoreCreator;
use Scrape\domain\creator\MonitorCreator;
use Scrape\domain\creator\ProjectCreator;
use Scrape\domain\creator\TaskCreator;
use Scrape\domain\deleter\IgnoreDeleter;
use Scrape\domain\deleter\ProjectDeleter;
use Scrape\domain\deleter\ResultDeleter;
use Scrape\domain\deleter\TaskDeleter;
use Scrape\domain\Downloader;
use Scrape\domain\IgnoreFilter;
use Scrape\domain\repository\IgnoreRepository;
use Scrape\domain\repository\ProjectRepository;
use Scrape\domain\repository\ResultRepository;
use Scrape\domain\repository\TaskRepository;
use Scrape\domain\Google;
use Scrape\domain\TaskResetter;
use Scrape\domain\TaskSuggestionRetriever;
use Scrape\models\Ignore;
use Scrape\models\Monitor;
use Scrape\models\Project;
use Scrape\models\Query;
use Scrape\models\Result;
use Scrape\models\Task;
use Scrape\models\TaskIntention;
use Scrape\models\TaskKeywordForm;
use Scrape\models\TaskPopularity;
use Scrape\models\TaskStatus;
use User\models\UserType;
use function GuzzleHttp\Psr7\str;

class DefaultController extends \CController
{
public function actionDownloadTask($id)
{

(new Downloader)->downloadByTask(TaskRepository::findOne($id));
}

public function actionDownloadProject($id)
{

(new Downloader)->downloadByProject(ProjectRepository::findOne($id));
}
}

But I get this error:


Exception has occurred.
Fatal error: Uncaught Error: Class "CController" not found in C:\xampp\htdocs\webScraper\protected\modules\scrape\controllers\DefaultController.php:44
Stack trace:
#0 {main}
thrown

On the class definition.


So my question is: how to tackle this inconvenience?


This is my index.php file:


<?php
use application\components\WebApplication;

define('DIR_ROOT',getcwd().DIRECTORY_SEPARATOR);

$autoload = DIR_ROOT . 'protected/vendor/autoload.php';
$config = DIR_ROOT . 'protected/config/main.php';
$yii = DIR_ROOT . 'protected/components/Yii.php';

// remove the following lines when in production mode
defined('YII_DEBUG') or define('YII_DEBUG',true);
// specify how many levels of call stack should be shown in each log message
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);

require_once($autoload);
require_once($yii);

include DIR_ROOT . 'protected/components/WebApplication.php';

(new WebApplication($config))->run();

As you can see I have $autoload defined in the index.php file. Or do you mean something else?



My Answer:
php
class MyController extends CController
{
public function actionIndex()
{
// Code to debug
}
}


To debug this controller action with Xdebug, you will need to set up Xdebug in your PHP configuration and configure your IDE to listen for Xdebug connections.

Here are the steps to debug the `actionIndex` method in the `MyController` class:

1. Make sure Xdebug is installed and enabled in your PHP configuration. You can check if Xdebug is installed by running `php -m | grep xdebug` in your terminal.

2. Configure your IDE to listen for Xdebug connections. This process will vary depending on your IDE, but most IDEs have a specific configuration setting for Xdebug.

3. Set a breakpoint in the `actionIndex` method by clicking on the line number where you want to pause the execution of the code.

4. Make a request to the `actionIndex` URL in your browser. This will trigger the Xdebug debugger to pause the execution of the code at the breakpoint you set.

5. Once the code execution is paused at the breakpoint, you can use your IDE's debugging tools to inspect variables, step through the code, and analyze the program flow.

By following these steps, you should be able to debug the `actionIndex` method in the `MyController` class using Xdebug in your Yii1 application.

Rate this post

5 of 5 based on 5250 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us