Good day to all. help me please.
The simplest task is required: to receive events with JSON data via REST from VK.com / Store them in the database. Further processing is a separate issue.
I installed the framework, added the BASIC application.
The application works at the address [url] https: // url_site / basic / web [/ url]
Added a table and generated a model for it through gii
\basic\models\Participants.php
<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "participants".
*
* @property int $id
* @property int $id_participants Идентификатор в ВК
* @property string $first_name Имя
* @property string $last_name Фамилия
* @property string $bdate День рождения
*/
class Participants extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'participants';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['id_participants', 'first_name', 'last_name', 'bdate'. 'reg_date'], 'required'],
[['id_participants'], 'integer'],
[['first_name', 'last_name'], 'string'],
[['bdate'], 'safe'],
[['reg_date'], 'safe'],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'id_participants' => 'Идентификатор в ВК',
'first_name' => 'Имя',
'last_name' => 'Фамилия',
'bdate' => 'День рождения',
'reg_date' => 'Дата и время когда добавился в группу',
];
}
}
Then I went through the description https://www.yiiframework.com/doc/guide/2.0/ru/rest-quick-start Quick start creating RESTfulAPI [/ url]
Created a controller
\basic\controllers\CallBackController.php
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace app\controllers;
use yii\rest\ActiveController;
class CallBackController extends ActiveController
{
public $modelClass = 'app\models\Participants';
//public $modelClass = 'basic\models\Participants';
}
On next step create php file for VK callback
\basic\web\callback.php
<?php
// NOTE: Make sure this file is not accessible when deployed to production
if (!in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1'])) {
die('You are not allowed to access this file.');
}
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'test');
require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../vendor/yiisoft/yii2/Yii.php';
$config = require __DIR__ . '/../config/rest.php';
(new yii\web\Application($config))->run();
well, for it I created a configuration file by copying web.php and adding to it according to the instructions
\basic\config\rest.php
<?php
$params = require __DIR__ . '/params.php';
$db = require __DIR__ . '/db.php';
$config = [
'id' => 'rest',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'aliases' => [
'@bower' => '@vendor/bower-asset',
'@npm' => '@vendor/npm-asset',
],
'components' => [
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => 'rest',
'parsers' => [
'application/json' => 'yii\web\JsonParser',
],
],
'cache' => [
'class' => 'yii\caching\FileCache',
],
'user' => [
'identityClass' => 'app\models\User',
'enableAutoLogin' => true,
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => true,
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'db' => $db,
'urlManager' => [
'enablePrettyUrl' => true,
'enableStrictParsing' => true,
'showScriptName' => false,
'rules' => [
['class' => 'yii\rest\UrlRule', 'controller' => 'callback'],
],
],
],
'params' => $params,
];
if (YII_ENV_DEV) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'yii\debug\Module',
// uncomment the following to add your IP if you are not connecting from localhost.
'allowedIPs' => ['127.0.0.1', '::1' , 'my_ip', 'ip_ssl_route'],
];
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
// uncomment the following to add your IP if you are not connecting from localhost.
'allowedIPs' => ['127.0.0.1', '::1', 'my_ip', 'ip_ssl_route'],
];
}
return $config;
as a result, I can’t get anything to get from REST
view-source:https://url_site/basic/callback/callback/1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /basic/callback/callback/1 was not found on this server.</p>
<hr>
<address>Apache/2.4.18 (Ubuntu) Server at url_site Port 80</address>
</body></html>
view-source:https://url_site/basic/callback/1
view-source:https://url_site/basic/web/callback/1
view-source:https://url_site/callback/1
same answers
What am I doing wrong?
Help please.