I'm new into learning phalcon, I'm trying to setup a phalcon project, I've managed to serve it on my localhost and it kinda works except for when an interaction with the database is needed. I got a mysql user which I granted all privileges to and a database, which is actually connected to the project, because I have access to every table in my GUI. The problem is, when I try to submit a form and my database configs are set up correctly, the serves gives me 502 Bad Gateway response. However, when I mess up the user's password in the db config on purpose, the serves displays this error :
SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' (using password: YES)
#0 [internal function]: PDO->__construct()
#1 [internal function]: Phalcon\Db\Adapter\Pdo\AbstractPdo->connect()
#2 /var/www/simple-admin/app/config/services.php(131): Phalcon\Db\Adapter\Pdo\AbstractPdo->__construct()
#3 [internal function]: Closure->{closure}()
#4 [internal function]: Phalcon\Di\Service->resolve()
#5 [internal function]: Phalcon\Di->get()
#6 [internal function]: Phalcon\Di->getShared()
#7 /var/www/simple-admin/app/controllers/IndexController.php(81): Phalcon\Di\Injectable->__get()
#8 [internal function]: PSA\Controllers\IndexController->signupAction()
#9 [internal function]: Phalcon\Dispatcher\AbstractDispatcher->callActionMethod()
#10 [internal function]: Phalcon\Dispatcher\AbstractDispatcher->dispatch()
#11 /var/www/simple-admin/public/index.php(43): Phalcon\Mvc\Application->handle()
#12 {main}
When I try to test If I can get the values of a table from the database in the controller to check If I have access to it, like this :
public function indexAction()
{
$user = Users::where('id',1);
var_dump($user);
}
The server gives me the following error :
The method 'where' doesn't exist on model 'PSA\Models\Users'
#0 /var/www/simple-admin/app/controllers/IndexController.php(38): Phalcon\Mvc\Model::__callStatic()
#1 [internal function]: PSA\Controllers\IndexController->indexAction()
#2 [internal function]: Phalcon\Dispatcher\AbstractDispatcher->callActionMethod()
#3 [internal function]: Phalcon\Dispatcher\AbstractDispatcher->dispatch()
#4 /var/www/simple-admin/public/index.php(43): Phalcon\Mvc\Application->handle()
#5 {main}
This is the Users Model :
<?php
declare(strict_types=1);
namespace PSA\Models;
use Phalcon\Mvc\Model;
use Phalcon\Security;
use Phalcon\Validation;
use Phalcon\Validation\Validator\Uniqueness;
use PSA\Models\UsersRoles;
/**
* All the users registered in the application
*/
class Users extends Model
{
/**
* #var integer
*/
public $id;
/**
* #var string
*/
public $name;
/**
* #var string
*/
public $email;
/**
* #var string
*/
public $password;
/**
* #var string
*/
public $mustChangePassword;
/**
* #var string
*/
public $banned;
/**
* #var string
*/
public $suspended;
/**
* #var string
*/
public $active;
public function initialize()
{
// Audit
$this->keepSnapshots(true);
$this->addBehavior(new \PSA\Models\Blameable());
$this->hasMany('id', UsersAuths::class, 'userID', [
'alias' => 'usersAuths',
'foreignKey' => [
'message' => 'User cannot be deleted because he/she has activity in the system',
],
]);
$this->hasMany('id', PasswordChanges::class, 'userID', [
'alias' => 'passwordChanges',
'foreignKey' => [
'message' => 'User cannot be deleted because he/she has activity in the system',
],
]);
$this->hasMany('id', ResetPasswords::class, 'userID', [
'alias' => 'resetPasswords',
'foreignKey' => [
'message' => 'User cannot be deleted because he/she has activity in the system',
],
]);
}
/**
* Before create the user assign a password
*/
public function beforeValidationOnCreate()
{
if (empty($this->password)) {
// Generate a plain temporary password
$tempPassword = preg_replace('/[^a-zA-Z0-9]/', '', base64_encode(openssl_random_pseudo_bytes(12)));
// The user must change its password in first login
$this->mustChangePassword = 1;
/** #var Security $security */
$security = $this->getDI()->getShared('security');
// Use this password as default
$this->password = $security->hash($tempPassword);
} else {
// The user must not change its password in first login
$this->mustChangePassword = 0;
}
// The account must be confirmed via e-mail
// Only require this if emails are turned on in the config, otherwise account is automatically active
if ($this->getDI()->get('config')->useMail) {
$this->active = 0;
} else {
$this->active = 1;
}
// The account is not suspended by default
$this->suspended = 0;
// The account is not banned by default
$this->banned = 0;
}
/**
* Send a confirmation e-mail to the user if the account is not active
*/
public function afterCreate()
{
// Only send the confirmation email if emails are turned on in the config
if ($this->getDI()->get('config')->useMail && $this->active == 0) {
$emailConfirmation = new EmailConfirmations();
$emailConfirmation->userID = $this->id;
if ($emailConfirmation->save()) {
$this->getDI()
->getFlash()
->notice('A confirmation mail has been sent to ' . $this->email);
}
}
}
/**
* Validate that emails are unique across users
*/
public function validation()
{
$validator = new Validation();
$validator->add('email', new Uniqueness([
"message" => "The email is already registered",
]));
return $this->validate($validator);
}
/**
* get all roles
*/
public function userRoles($userID)
{
return UsersRoles::find("userID = '$userID'");
}
/**
* get all roleID
*/
public function userRolesID($userID)
{
$result = [];
$usersRoles = UsersRoles::find("userID = '$userID'");
foreach ($usersRoles as $value) {
$result[] = $value->roleID;
}
return $result;
}
}
Config.php :
<?php
/*
* Modified: prepend directory path of current file, because of this file own different ENV under between Apache and command line.
* NOTE: please remove this comment.
*/
use Phalcon\Config;
defined('BASE_PATH') || define('BASE_PATH', getenv('BASE_PATH') ?: realpath(dirname(__FILE__) . '/../..'));
defined('APP_PATH') || define('APP_PATH', BASE_PATH . '/app');
return new Config([
'database' => [
'adapter' => 'mysql',
'host' => 'localhost',
'username' => 'root',
'password' => 'Nikusha_38',
'dbname' => 'test2',
'charset' => 'utf8',
],
'application' => [
'baseUri' => '/',
'publicUrl' => 'simple-admin.sitchi.dev',
'appDir' => APP_PATH . '/',
'controllersDir' => APP_PATH . '/controllers/',
'formsDir' => APP_PATH . '/forms/',
'helpersDir' => APP_PATH . '/helpers/',
'libraryDir' => APP_PATH . '/library/',
'migrationsDir' => APP_PATH . '/migrations/',
'modelsDir' => APP_PATH . '/models/',
'viewsDir' => APP_PATH . '/views/',
'cacheDir' => BASE_PATH . '/cache/',
'cryptSalt' => 'eEAfR|_&G&f,+vU]:jFr!!A&+71w1Ms9~8_4L!<#[N#DyaIP_2My|:+.u>/6m,$D'
],
'mail' => [
'fromName' => 'Simple Admin',
'fromEmail' => 'info#sitchi.dev',
'smtp' => [
'server' => 'smtp.sitchi.dev',
'port' => 465,
'security' => 'ssl',
'username' => '',
'password' => '',
],
],
'logger' => [
'path' => BASE_PATH . '/logs/',
'filename' => 'application.log',
'format' => '%date% [%type%] %message%',
'date' => 'Y-m-d H:i:s',
],
// Set to false to disable sending emails (for use in test environment)
'useMail' => false
]);
I tried looking this up but can't seem to find anything relatable. Thanks in advance for the help!
Try changing:
{
$user = Users::where('id',1);
var_dump($user);
}
to:
{
$user = Users::find('id=1');
var_dump($user);
}
Related
Good afternoon.
I have created my own filter in Yii2 basic project:
class LanguageFilter extends Behavior
{
/**
* #var string
*/
public $shortLanguage;
/**
* Declares event handlers for the [[owner]]'s events.
* #return array events (array keys) and the corresponding event handler methods (array values).
*/
public function events()
{
return [Controller::EVENT_BEFORE_ACTION => 'beforeAction'];
}
/**
* #param ActionEvent $event
* #return bool
* #throws BadRequestHttpException
*/
public function beforeAction($event)
{
if (null === $this->shortLanguage){
throw new BadRequestHttpException('Parameter "shortLanguage" is not defined.');
}
$langModel = Language::find()->where([
'shortName' => $this->shortLanguage
])->one();
if (null === $langModel){
throw new BadRequestHttpException('There are not any data for language: '.$this->shortLanguage);
}
Yii::$app->language = $langModel->locale;
return true;
}
}
And use it in controller:
class BaseController extends Controller
{
/**
* #var string
*/
protected $shortLanguage;
/**
* Initialize.
*/
public function init()
{
$this->defaultAction = 'index';
$this->layout = '#app/views/layouts/base';
$this->shortLanguage = Yii::$app->request->get('shortLanguage');
$this->view->params['shortLanguage'] = $this->shortLanguage;
$this->view->params['pages'] = Page::getMenu();
parent::init();
}
/**
* #inheritdoc
*/
public function behaviors()
{
return [
'language' => [
'class' => LanguageFilter::class,
'shortLanguage' => $this->shortLanguage
],
'access' => [
'class' => AccessControl::class,
'rules' => [
[
'allow' => true,
'actions' => ['reg', 'login'],
'roles' => ['?'],
],
[
'allow' => true,
'actions' => ['logout'],
'roles' => ['#'],
],
[
'allow' => true,
'actions' => ['index', 'about', 'contact'],
'roles' => ['?', '#'],
],
[
'allow' => true,
'actions' => ['error'],
'roles' => ['?', '#'],
],
],
],
'verbs' => [
'class' => VerbFilter::class,
'actions' => [
'index' => ['get'],
'logout' => ['post', 'get'],
],
],
];
}
/**
* #inheritdoc
*/
public function actions()
{
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
];
}
}
In web configuration file error handler:
'components' => [
...
...
'errorHandler' => [
'errorAction' => 'base/error',
],
...
...
]
But when the filter throws an exception, the error handler displays an error message WITHOUT TEMPLATE !!! And with another mistake.
An Error occurred while handling another error:
yii\web\BadRequestHttpException: There are not any data for language: fr in C:\xampp\htdocs\pack-develop\filters\LanguageFilter.php:44
Stack trace:
#0 [internal function]: app\filters\LanguageFilter->beforeAction(Object(yii\base\ActionEvent))
#1 C:\xampp\htdocs\pack-develop\vendor\yiisoft\yii2\base\Component.php(627): call_user_func(Array, Object(yii\base\ActionEvent))
#2 C:\xampp\htdocs\pack-develop\vendor\yiisoft\yii2\base\Controller.php(274): yii\base\Component->trigger('beforeAction', Object(yii\base\ActionEvent))
#3 C:\xampp\htdocs\pack-develop\vendor\yiisoft\yii2\web\Controller.php(164): yii\base\Controller->beforeAction(Object(yii\web\ErrorAction))
#4 C:\xampp\htdocs\pack-develop\vendor\yiisoft\yii2\base\Controller.php(155): yii\web\Controller->beforeAction(Object(yii\web\ErrorAction))
#5 C:\xampp\htdocs\pack-develop\vendor\yiisoft\yii2\base\Module.php(528): yii\base\Controller->runAction('error', Array)
#6 C:\xampp\htdocs\pack-develop\vendor\yiisoft\yii2\web\ErrorHandler.php(108): yii\base\Module->runAction('base/error')
#7 C:\xampp\htdocs\pack-develop\vendor\yiisoft\yii2\base\ErrorHandler.php(111): yii\web\ErrorHandler->renderException(Object(yii\web\BadRequestHttpException))
#8 [internal function]: yii\base\ErrorHandler->handleException(Object(yii\web\BadRequestHttpException))
#9 {main}
Previous exception:
yii\web\BadRequestHttpException: There are not any data for language: fr in C:\xampp\htdocs\pack-develop\filters\LanguageFilter.php:44
Stack trace:
#0 [internal function]: app\filters\LanguageFilter->beforeAction(Object(yii\base\ActionEvent))
#1 C:\xampp\htdocs\pack-develop\vendor\yiisoft\yii2\base\Component.php(627): call_user_func(Array, Object(yii\base\ActionEvent))
#2 C:\xampp\htdocs\pack-develop\vendor\yiisoft\yii2\base\Controller.php(274): yii\base\Component->trigger('beforeAction', Object(yii\base\ActionEvent))
#3 C:\xampp\htdocs\pack-develop\vendor\yiisoft\yii2\web\Controller.php(164): yii\base\Controller->beforeAction(Object(yii\base\InlineAction))
#4 C:\xampp\htdocs\pack-develop\vendor\yiisoft\yii2\base\Controller.php(155): yii\web\Controller->beforeAction(Object(yii\base\InlineAction))
#5 C:\xampp\htdocs\pack-develop\vendor\yiisoft\yii2\base\Module.php(528): yii\base\Controller->runAction('index', Array)
#6 C:\xampp\htdocs\pack-develop\vendor\yiisoft\yii2\web\Application.php(103): yii\base\Module->runAction('home/index', Array)
#7 C:\xampp\htdocs\pack-develop\vendor\yiisoft\yii2\base\Application.php(386): yii\web\Application->handleRequest(Object(yii\web\Request))
#8 C:\xampp\htdocs\pack-develop\web\index.php(33): yii\base\Application->run()
#9 {main}
The strange thing is that when other filters (AccessControl, VerbFilter) issue exceptions, the error handler displays an error message through the view template normally.
Please help me to understand the reason of it!
It's a filter not behavior, I have modified your filter that works.
use Yii;
use yii\web\Controller;
use yii\base\ActionFilter;
use yii\web\BadRequestHttpException;
class LanguageFilter extends ActionFilter
{
/**
* #var string
*/
public $shortLanguage;
/**
* #param ActionEvent $action
* #return bool
* #throws BadRequestHttpException
*/
public function beforeAction($action)
{
if ($this->shortLanguage === null && !$action instanceof yii\web\ErrorAction)) {
throw new BadRequestHttpException('Parameter "shortLanguage" is not defined.');
}
$langModel = Language::find()->where([
'shortName' => $this->shortLanguage,
])->one();
if ($langModel === null && !$action instanceof yii\web\ErrorAction) {
throw new BadRequestHttpException('There are not any data for language: ' . $this->shortLanguage);
}
Yii::$app->language = $langModel->locale;
return true; //return parent::beforeAction($action);
}
}
After a long time away from Zend, I need to get back into it again.
My last work on Zend Framework was in 2016. Now I tried to install Zend Framework 3 with doctrine and get stuck.
What I did:
Build the skeleton app with composer
composer create-project -s dev zendframework/skeleton-application path/to/install
Did not use the minimal installation and said y on all options. Did update of composer and installed Zend Framework:
composer self-update
composer install
I started the machine and entered it: vagrant up && vagrant ssh
I required doctrine require doctrine/doctrine-orm-module and configured it in module.config.php as follow:
'doctrine' => [
'connection' => [
'orm_default' => [
'driverClass' => PDOMySqlDriver::class,
'params' => [
'host' => '127.0.0.1',
'user' => 'root',
'password' => 'r00t',
'dbname' => 'zftest',
]
],
],
],
Then I wrote a controller factory to inject the entity manager:
namespace Application\Controller\Factory;
use Application\Entity\User;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\Factory\FactoryInterface;
use Application\Controller\IndexController;
/**
* This is the factory for IndexController. Its purpose is to instantiate the
* controller.
*/
class IndexControllerFactory implements FactoryInterface
{
public function __invoke(ContainerInterface $container,
$requestedName, array $options = null)
{
$entityManager = $container->get('doctrine.entitymanager.orm_default');
// Instantiate the controller and inject dependencies
return new IndexController($entityManager);
}
}
Added an entity to the codebase:
namespace Application\Entity;
/**
* #ORM\Entity
* #ORM\Table(name="user")
*/
class User
{
/**
* #ORM\Id
* #ORM\GeneratedValue
* #ORM\Column(name="id")
*/
protected $id;
/**
* #ORM\Column(name="nick")
*/
protected $nick;
....
}
I tried to create the mysql tables via doctrine using this entity:
./vendor/bin/doctrine-module orm:schema-tool:create
The table was not created and I got this error:
"No Metadata Classes to process."
I tried to test doctrine:
./vendor/bin/doctrine-module orm:validate-schema
and it seems to be working:
[Mapping] OK - The mapping files are correct.
[Database] OK - The database schema is in sync with the mapping files.
Also tried in the controller to load the tables which I created manually:
class IndexController extends AbstractActionController
{
/**
* Doctrine entity manager.
* #var Doctrine\ORM\EntityManager
*/
private $entityManager;
// Constructor is used to inject dependencies into the service.
/**
* IndexController constructor.
* #param $entityManager
*/
public function __construct($entityManager)
{
$this->entityManager = $entityManager;
}
public function indexAction()
{
$users = $this->entityManager->getRepository('Application\Entity\User')->findAll();
return new ViewModel();
}
}
Which caused following error:
An error occurred
An error occurred during execution; please try again later.
Additional information: Doctrine\Common\Persistence\Mapping\MappingException
File: /var/www/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/MappingException.php:37
Message: The class 'Application\Entity\User' was not found in the chain configured namespaces
Stack trace:
#0 /var/www/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/Driver/MappingDriverChain.php(112): Doctrine\Common\Persistence\Mapping\MappingException::classNotFoundInNamespaces('Application\\Ent...', Array)
#1 /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php(151): Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain->loadMetadataForClass('Application\\Ent...', Object(Doctrine\ORM\Mapping\ClassMetadata))
#2 /var/www/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php(332): Doctrine\ORM\Mapping\ClassMetadataFactory->doLoadMetadata(Object(Doctrine\ORM\Mapping\ClassMetadata), NULL, false, Array)
#3 /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php(78): Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->loadMetadata('Application\\Ent...')
#4 /var/www/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php(216): Doctrine\ORM\Mapping\ClassMetadataFactory->loadMetadata('Application\\Ent...')
#5 /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php(281): Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getMetadataFor('Application\\Ent...')
#6 /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/Repository/DefaultRepositoryFactory.php(44): Doctrine\ORM\EntityManager->getClassMetadata('Application\\Ent...')
#7 /var/www/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php(698): Doctrine\ORM\Repository\DefaultRepositoryFactory->getRepository(Object(Doctrine\ORM\EntityManager), 'Application\\Ent...')
#8 /var/www/module/Application/src/Controller/IndexController.php(35): Doctrine\ORM\EntityManager->getRepository('Application\\Ent...')
#9 /var/www/vendor/zendframework/zend-mvc/src/Controller/AbstractActionController.php(78): Application\Controller\IndexController->indexAction()
#10 /var/www/vendor/zendframework/zend-eventmanager/src/EventManager.php(322): Zend\Mvc\Controller\AbstractActionController->onDispatch(Object(Zend\Mvc\MvcEvent))
#11 /var/www/vendor/zendframework/zend-eventmanager/src/EventManager.php(179): Zend\EventManager\EventManager->triggerListeners(Object(Zend\Mvc\MvcEvent), Object(Closure))
#12 /var/www/vendor/zendframework/zend-mvc/src/Controller/AbstractController.php(106): Zend\EventManager\EventManager->triggerEventUntil(Object(Closure), Object(Zend\Mvc\MvcEvent))
#13 /var/www/vendor/zendframework/zend-mvc/src/DispatchListener.php(138): Zend\Mvc\Controller\AbstractController->dispatch(Object(Zend\Http\PhpEnvironment\Request), Object(Zend\Http\PhpEnvironment\Response))
#14 /var/www/vendor/zendframework/zend-eventmanager/src/EventManager.php(322): Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent))
#15 /var/www/vendor/zendframework/zend-eventmanager/src/EventManager.php(179): Zend\EventManager\EventManager->triggerListeners(Object(Zend\Mvc\MvcEvent), Object(Closure))
#16 /var/www/vendor/zendframework/zend-mvc/src/Application.php(332): Zend\EventManager\EventManager->triggerEventUntil(Object(Closure), Object(Zend\Mvc\MvcEvent))
#17 /var/www/public/index.php(40): Zend\Mvc\Application->run()
#18 {main}
Can someone give me a hint what I am missing?
It looks like you have no definition of where entities should be found.
Here's the link to the missing bit in your code:
DoctrineORMModule Documentation
At first sight your error seems to tell us he can't find 'Application\Entity\User'.
At start, Doctrine doesn't know anything about your namespaces.
Doctrine uses an AnnotationDriver to get informed about the location of your entities.
So at your step 5, where you specify module.config.php, you will need to add the following code into the mix:
<?php
namespace Application;
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
return [
// ...
'doctrine' => [
'driver' => [
__NAMESPACE__ . '_driver' => [
'class' => AnnotationDriver::class,
'cache' => 'array',
'paths' => [__DIR__ . '/../src/Entity']
],
'orm_default' => [
'drivers' => [
__NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_driver'
]
]
]
]
];
And offcourse you'll need to setup to paths to your setup.
I created my first Laravel package out of some old PHP script for Teamspeak auth service. The main app was running Laravel 4, but has now been upgraded to Laravel 5. My package worked before, but now does not.
The error -
[2017-08-17 22:04:29] local.ERROR: ErrorException: Trying to get property of non-object in /apppath/vendor/eveseat/services/src/Settings/Settings.php:86
Stack trace:
#0 /apppath/vendor/eveseat/services/src/Settings/Settings.php(86): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Trying to get p...', '/apppath/$
#1 /apppath/vendor/laravel/framework/src/Illuminate/Cache/Repository.php(349): Seat\Services\Settings\Settings::Seat\Services\Settings\{closure}()
#2 /apppath/vendor/laravel/framework/src/Illuminate/Cache/CacheManager.php(301): Illuminate\Cache\Repository->rememberForever('tHKT2R21Aa1VLKh...', Object(Closure))
#3 /apppath/bootstrap/cache/compiled.php(6468): Illuminate\Cache\CacheManager->__call('rememberForever', Array)
#4 /apppath/vendor/eveseat/services/src/Settings/Settings.php(101): Illuminate\Support\Facades\Facade::__callStatic('rememberForever', Array)
#5 /apppath/vendor/eveseat/services/src/Helpers/helpers.php(289): Seat\Services\Settings\Settings::get('main_character_...')
#6 /apppath/vendor/package/mypackage/src/Http/Controllers/Ts3Controller.php(33): setting('main_character_...')
#7 [internal function]: Seat\Ts3\Http\Controllers\Ts3Controller->getControls()
The offending function in Ts3Controller -
$APIcharacterID = $pheal->eveScope->CharacterID(array("names" => setting('main_character_name')));
The same call is made elsewhere in the parent package and still works, so the object still exists.
Pheal is not throwing errors and is completing API calls elswhere.
The Model being referenced -
namespace Seat\Services\Settings;
use Seat\Services\Models\UserSetting;
/**
* Class Profile.
* #package Seat\Services\Settings
*/
class Profile extends Settings
{
/**
* The options available for this Setting type.
*
* #var array
*/
public static $options = [
'sidebar' => ['sidebar-full', 'sidebar-collapse'],
'skins' => [
'skin-blue', 'skin-black', 'skin-purple', 'skin-green',
'skin-red', 'skin-yellow', 'skin-blue-light', 'skin-black-light',
'skin-purple-light', 'skin-green-light', 'skin-red-light',
'skin-yellow-light',
],
'thousand_seperator' => [' ', ',', '.'],
'decimal_seperator' => [',', '.'],
'mail_threads' => ['yes', 'no'],
];
/**
* #var string
*/
protected static $prefix = 'profile';
/**
* #var
*/
protected static $model = UserSetting::class;
/**
* #var string
*/
protected static $scope = 'user';
/**
* #var array
*/
protected static $defaults = [
// UI
'sidebar' => 'sidebar-full',
'skin' => 'skin-black',
'language' => 'en',
'mail_threads' => 'yes',
// Main Character
'main_character_id' => 1,
'main_character_name' => null,
// Numbers
'thousand_seperator' => ' ',
'decimal_seperator' => '.',
// Notifications
'email_notifications' => 'no',
// Multi factor authentication
'require_mfa' => 'no',
];
}
Which is referenced in my controller here -
use Seat\Services\Settings\Profile;
I'm very new to Yii framework.
I did only basic compulsory steps in setting up advance Yii. But it gives the following error when I try load the index.php(localhost:8888/new/advanced/frontend/web/index.php) in frontend as well as the index.php (localhost:8888/new/advanced/backend/web/index.php) in the backend.
Things I have done from the beginning:
Downloaded the advanced Yii framework & extracted it to the htdocs
Run the command php init in the terminal.that's all...
I tried this solution yii2-error-the-view-file-does-not-exist.. but it didn't worked
Error
An Error occurred while handling another error:
exception 'yii\base\InvalidParamException' with message 'The view file does not exist: /Applications/MAMP/htdocs/SMS_Messenger/vendor/yiisoft/yii2/views/errorHandler/exception.php' in /Applications/MAMP/htdocs/new/advanced/vendor/yiisoft/yii2/base/View.php:226
Stack trace:
#0 /Applications/MAMP/htdocs/new/advanced/vendor/yiisoft/yii2/web/ErrorHandler.php(241): yii\base\View->renderFile('#yii/views/erro...', Array, Object(yii\web\ErrorHandler))
#1 /Applications/MAMP/htdocs/new/advanced/vendor/yiisoft/yii2/web/ErrorHandler.php(112): yii\web\ErrorHandler->renderFile('#yii/views/erro...', Array)
#2 /Applications/MAMP/htdocs/new/advanced/vendor/yiisoft/yii2/base/ErrorHandler.php(109): yii\web\ErrorHandler->renderException(Object(yii\base\InvalidParamException))
#3 [internal function]: yii\base\ErrorHandler->handleException(Object(yii\base\InvalidParamException))
#4 {main}
Previous exception:
exception 'yii\base\InvalidParamException' with message 'The file or directory to be published does not exist: /Applications/MAMP/htdocs/SMS_Messenger/vendor/yiisoft/yii2/assets' in /Applications/MAMP/htdocs/new/advanced/vendor/yiisoft/yii2/web/AssetManager.php:452
Stack trace:
#0 /Applications/MAMP/htdocs/new/advanced/vendor/yiisoft/yii2/web/AssetBundle.php(179): yii\web\AssetManager->publish('/Applications/M...', Array)
#1 /Applications/MAMP/htdocs/new/advanced/vendor/yiisoft/yii2/web/AssetManager.php(266): yii\web\AssetBundle->publish(Object(yii\web\AssetManager))
#2 /Applications/MAMP/htdocs/new/advanced/vendor/yiisoft/yii2/web/AssetManager.php(237): yii\web\AssetManager->loadBundle('yii\\web\\YiiAsse...', Array, true)
#3 /Applications/MAMP/htdocs/new/advanced/vendor/yiisoft/yii2/web/View.php(284): yii\web\AssetManager->getBundle('yii\\web\\YiiAsse...')
#4 /Applications/MAMP/htdocs/new/advanced/vendor/yiisoft/yii2/web/View.php(289): yii\web\View->registerAssetBundle('yii\\web\\YiiAsse...', NULL)
#5 /Applications/MAMP/htdocs/new/advanced/vendor/yiisoft/yii2/web/AssetBundle.php(123): yii\web\View->registerAssetBundle('frontend\\assets...')
#6 /Applications/MAMP/htdocs/new/advanced/frontend/views/layouts/main.php(13): yii\web\AssetBundle::register(Object(yii\web\View))
#7 /Applications/MAMP/htdocs/new/advanced/vendor/yiisoft/yii2/base/View.php(325): require('/Applications/M...')
#8 /Applications/MAMP/htdocs/new/advanced/vendor/yiisoft/yii2/base/View.php(247): yii\base\View->renderPhpFile('/Applications/M...', Array)
#9 /Applications/MAMP/htdocs/new/advanced/vendor/yiisoft/yii2/base/Controller.php(392): yii\base\View->renderFile('/Applications/M...', Array, Object(frontend\controllers\SiteController))
#10 /Applications/MAMP/htdocs/new/advanced/vendor/yiisoft/yii2/base/Controller.php(378): yii\base\Controller->renderContent('<div class="sit...')
#11 /Applications/MAMP/htdocs/new/advanced/frontend/controllers/SiteController.php(75): yii\base\Controller->render('index')
#12 [internal function]: frontend\controllers\SiteController->actionIndex()
#13 /Applications/MAMP/htdocs/new/advanced/vendor/yiisoft/yii2/base/InlineAction.php(55): call_user_func_array(Array, Array)
#14 /Applications/MAMP/htdocs/new/advanced/vendor/yiisoft/yii2/base/Controller.php(154): yii\base\InlineAction->runWithParams(Array)
#15 /Applications/MAMP/htdocs/new/advanced/vendor/yiisoft/yii2/base/Module.php(454): yii\base\Controller->runAction('', Array)
#16 /Applications/MAMP/htdocs/new/advanced/vendor/yiisoft/yii2/web/Application.php(84): yii\base\Module->runAction('', Array)
#17 /Applications/MAMP/htdocs/new/advanced/vendor/yiisoft/yii2/base/Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))
#18 /Applications/MAMP/htdocs/new/advanced/frontend/web/index.php(18): yii\base\Application->run()
#19 {main}
frontend sitecontroller.php
<?php
namespace frontend\controllers;
use Yii;
use common\models\LoginForm;
use frontend\models\PasswordResetRequestForm;
use frontend\models\ResetPasswordForm;
use frontend\models\SignupForm;
use frontend\models\ContactForm;
use yii\base\InvalidParamException;
use yii\web\BadRequestHttpException;
use yii\web\Controller;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
class SiteController extends Controller
{
/**
* #inheritdoc
*/
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'only' => ['logout', 'signup'],
'rules' => [
[
'actions' => ['signup'],
'allow' => true,
'roles' => ['?'],
],
[
'actions' => ['logout'],
'allow' => true,
'roles' => ['#'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'logout' => ['post'],
],
],
];
}
/**
* #inheritdoc
*/
public function actions()
{
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
'captcha' => [
'class' => 'yii\captcha\CaptchaAction',
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
],
];
}
/**
* Displays homepage.
*
* #return mixed
*/
public function actionIndex()
{
return $this->render('index');
}
//other codes
My environment is Mac OS 10.11 El capitain
since I'm very newbie to Yii & I haven't changed the default code its hard to figure out the problem.
Hope for any suggestion
You don't have vendor directory.
Run composer from command line. Probably you must first install composer. Then in root dir of advanced project run:
composer install
or
php composer install
I want to access a PostgreSQL Database with Doctrine 2 in a Zend 2 Application, but I get the error, that the table I want to access is not defined.
The same access on a MySQL Database works fine.
My Doctrine configuration (local.php) is:
return array(
'doctrine' => array(
'connection' => array(
'orm_default' => array(
// MySQL - Config
// 'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
// 'params' => array(
// 'host' => '192.168.1.100',
// 'port' => '3306',
// 'user' => 'user',
// 'password' => 'password',
// 'dbname' => 'mydb',
// 'charset' => 'utf8',
// ),
// PostgreSQL
'driverClass' => 'Doctrine\DBAL\Driver\PDOPgSql\Driver',
'params' => array(
'host' => '192.168.1.100',
'port' => '5432',
'user' => 'user',
'password' => 'password',
'dbname' => 'mydb',
'charset' => 'utf8',
),
),
),
),
);
My Controller tries to display an Entity "Horse":
class HorsesController extends AbstractActionController
{
/**
* #var Doctrine\ORM\EntityManager
*/
protected $em;
public function getEntityManager()
{
if (null === $this->em) {
$this->em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
}
return $this->em;
}
/**
* The default action - show the home page
*/
public function indexAction()
{
$id = (int)$this->getEvent()->getRouteMatch()->getParam('id');
$horse = $this->getEntityManager()->find('Doctrine2mapper\Entity\Horse', $id);
return new ViewModel(array(
'horse' => $horse,
));
}
}
The Entity Horse is:
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Zend\Form\Annotation; // !!!! Absolutely neccessary
use Zend\Db\Sql\Ddl\Column\BigInteger;
/**
* Horses
*
* #ORM\Table(name="Horse")
* #ORM\Entity(repositoryClass="Doctrine2mapper\Entity\Repository\HorseRepository")
* #Annotation\Name("Horse")
* #Annotation\Hydrator("Zend\Stdlib\Hydrator\ClassMethods")
*/
class Horse
{
/**
* #var integer
*
* #ORM\Column(name="id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
* #Annotation\Exclude()
*/
private $id;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
.
.
.
(many attributes, getter and setter)
When trying to access PostgreSQL I get this error:
An exception occurred while executing 'SELECT t0.id AS id1, ...
FROM Horse t0 WHERE t0.id = ?' with params [1]:
SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "horse" does not exist
LINE 1: ...ated AS created29, t0.modified AS modified30 FROM Horse t0 W...
I have a PostgreSQL Database "mydb" with the schema "public" and the table "Horse"
-- Table: "Horse"
CREATE TABLE "Horse"
(
id serial NOT NULL,
.
.
.
);
exists and can be accessed using pgAdminIII.
Any help is welcome!
Best regards
rholtermann
Found the answer, now it works.
I just had to add the schema and had to escape it a little:
In my Horse-Entity:
#ORM\Table("Horse")
had to be replaced with:
#ORM\Table(name="""public"".""Horse""")
I got the hint from here