Trying to get property of non-object in Laravel 5 after upgrade - php

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;

Related

Can't connect phalcon project with mysql database

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);
}

Yii2 own filter "An Error occurred while handling another error"

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);
}
}

Moving PHP framework from one host to another, generates Uknown record property / related component error

I need to move a website from one hosting to another, there is a php app that uses the Zend framework.
Moving the files and the database i managed to reconfigure the database access, however an error appears on the page:
Fatal error:
Uncaught Doctrine_Record_UnknownPropertyException: Unknown record property / related component "Array" on "Model_User_Group" in /home/oneclou3/public_html/app/library/Doctrine/Record/Filter/Standard.php:55
Stack trace:
#0 /home/oneclou3/public_html/app/library/Doctrine/Record.php(1395): Doctrine_Record_Filter_Standard->filterGet(Object(Model_User_Group), 'Array')
#1 /home/oneclou3/public_html/app/library/Doctrine/Record.php(1350): Doctrine_Record->_get('Array', true)
#2 /home/oneclou3/public_html/app/library/Doctrine/Access.php(72): Doctrine_Record->get('Array')
#3 /home/oneclou3/public_html/app/library/Doctrine/Query/Abstract.php(1121): Doctrine_Access->__get('Array')
#4 /home/oneclou3/public_html/app/library/Doctrine/Query/Abstract.php(1008): Doctrine_Query_Abstract->_preQuery(Array)
#5 /home/oneclou3/public_html/app/library/Doctrine/Table.php(1649): Doctrine_Query_Abstract->execute(Array, 3)
#6 /home/oneclou3/public_html/app/library/Zex/Auth/Abstract.php(229): Doctrine_Table->findAll(3)
#7 /home/oneclou3/p in /home/oneclou3/public_html/app/library/Doctrine/Record/Filter/Standard.php on line 55
I'm not sure how to solve this, the Model_User_Group just extends a base class:
<?php
/**
* Model_User_Group
*
* This class has been auto-generated by the Doctrine ORM Framework
*
* #package ##PACKAGE##
* #subpackage ##SUBPACKAGE##
* #author ##NAME## <##EMAIL##>
* #version SVN: $Id: Builder.php 7490 2010-03-29 19:53:27Z jwage $
*/
class Model_User_Group extends BaseModel_User_Group
{
}
base:
<?php
/**
* BaseModel_User_Group
*
* This class has been auto-generated by the Doctrine ORM Framework
*
* #property integer $id
* #property string $title
* #property string $uid
* #property string $model
* #property Doctrine_Collection $Model_User
*
* #package ##PACKAGE##
* #subpackage ##SUBPACKAGE##
* #author ##NAME## <##EMAIL##>
* #version SVN: $Id: Builder.php 7490 2010-03-29 19:53:27Z jwage $
*/
abstract class BaseModel_User_Group extends Doctrine_Record
{
public function setTableDefinition()
{
$this->setTableName('groups');
$this->hasColumn('id', 'integer', 4, array(
'type' => 'integer',
'primary' => true,
'autoincrement' => true,
'length' => '4',
));
$this->hasColumn('title', 'string', 255, array(
'type' => 'string',
'notnull' => true,
'length' => '255',
));
$this->hasColumn('uid', 'string', 50, array(
'type' => 'string',
'notnull' => true,
'length' => '50',
));
$this->hasColumn('model', 'string', 255, array(
'type' => 'string',
'notnull' => true,
'length' => '255',
));
$this->index('uid', array(
'fields' =>
array(
0 => 'uid',
),
'type' => 'unique',
));
$this->option('collate', 'utf8_general_ci');
$this->option('charset', 'utf8');
$this->option('type', 'InnoDB');
}
public function setUp()
{
parent::setUp();
$this->hasMany('Model_User', array(
'local' => 'id',
'foreign' => 'groups_id'));
$timestampable0 = new Doctrine_Template_Timestampable();
$this->actAs($timestampable0);
}
}
Not sure what else i need to provide, thanks in advance.

Problems to integrate Doctrine in Zend3 project

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.

Yii PHP- Property is not defined

I'm managing a site built on the Yii Framework and very randomly started to get the following error. Not exactly sure how or why this started happening since the source hasn't been touch.
Appreciate any help. Thanks!
CException
Description
Property "feature.mobile_hero_img" is not defined.
Source File
/data/www.zoomiezoom.com/yii/framework/db/ar/CActiveRecord.php(106)
00094: */
00095: public function __get($name)
00096: {
00097: if(isset($this->_attributes[$name]))
00098: return $this->_attributes[$name];
00099: else if(isset($this->getMetaData()->columns[$name]))
00100: return null;
00101: else if(isset($this->_related[$name]))
00102: return $this->_related[$name];
00103: else if(isset($this->getMetaData()->relations[$name]))
00104: return $this->getRelated($name);
00105: else
00106: return parent::__get($name);
00107: }
00108:
00109: /**
00110: * PHP setter magic method.
00111: * This method is overridden so that AR attributes can be accessed like properties.
00112: * #param string property name
00113: * #param mixed property value
00114: */
00115: public function __set($name,$value)
00116: {
00117: if($this->setAttribute($name,$value)===false)
00118: {
Stack Trace
#0 /data/www.zoomiezoom.com/yii/framework/db/ar/CActiveRecord.php(106): CComponent->__get('mobile_hero_img')
#1 /data/www.zoomiezoom.com/yii/framework/web/helpers/CHtml.php(1624): CActiveRecord->__get('mobile_hero_img')
#2 /data/www.zoomiezoom.com/yii/framework/web/helpers/CHtml.php(1100): CHtml::activeInputField('text', Object(feature), 'mobile_hero_img', Array)
#3 /data/www.zoomiezoom.com/protected/views/feature/_form.php(74): CHtml::activeTextField(Object(feature), 'mobile_hero_img', Array)
#4 /data/www.zoomiezoom.com/yii/framework/web/CBaseController.php(119): require('/data/www.theax...')
#5 /data/www.zoomiezoom.com/yii/framework/web/CBaseController.php(88): CBaseController->renderInternal('/data/www.theax...', Array, true)
#6 /data/www.zoomiezoom.com/yii/framework/web/CController.php(732): CBaseController->renderFile('/data/www.theax...', Array, true)
#7 /data/www.zoomiezoom.com/protected/views/feature/create.php(14): CController->renderPartial('_form', Array)
#8 /data/www.zoomiezoom.com/yii/framework/web/CBaseController.php(119): require('/data/www.theax...')
#9 /data/www.zoomiezoom.com/yii/framework/web/CBaseController.php(88): CBaseController->renderInternal('/data/www.theax...', Array, true)
#10 /data/www.zoomiezoom.com/yii/framework/web/CController.php(732): CBaseController->renderFile('/data/www.theax...', Array, true)
#11 /data/www.zoomiezoom.com/yii/framework/web/CController.php(671): CController->renderPartial('create', Array, true)
#12 /data/www.zoomiezoom.com/protected/controllers/FeatureController.php(71): CController->render('create', Array)
#13 /data/www.zoomiezoom.com/yii/framework/web/actions/CInlineAction.php(32): FeatureController->actionCreate()
#14 /data/www.zoomiezoom.com/yii/framework/web/CController.php(300): CInlineAction->run()
#15 /data/www.zoomiezoom.com/yii/framework/web/filters/CFilterChain.php(129): CController->runAction(Object(CInlineAction))
#16 /data/www.zoomiezoom.com/yii/framework/web/filters/CFilter.php(41): CFilterChain->run()
#17 /data/www.zoomiezoom.com/yii/framework/web/CController.php(983): CFilter->filter(Object(CFilterChain))
#18 /data/www.zoomiezoom.com/yii/framework/web/filters/CInlineFilter.php(59): CController->filterAccessControl(Object(CFilterChain))
#19 /data/www.zoomiezoom.com/yii/framework/web/filters/CFilterChain.php(126): CInlineFilter->filter(Object(CFilterChain))
#20 /data/www.zoomiezoom.com/yii/framework/web/CController.php(283): CFilterChain->run()
#21 /data/www.zoomiezoom.com/yii/framework/web/CController.php(257): CController->runActionWithFilters(Object(CInlineAction), Array)
#22 /data/www.zoomiezoom.com/yii/framework/web/CWebApplication.php(320): CController->run('create')
#23 /data/www.zoomiezoom.com/yii/framework/web/CWebApplication.php(120): CWebApplication->runController('feature/create')
#24 /data/www.zoomiezoom.com/yii/framework/base/CApplication.php(135): CWebApplication->processRequest()
#25 /data/www.zoomiezoom.com/public_html/admin_tae/index.php(13): CApplication->run()
#26 {main}
schema for feature.php
<?php
class feature extends CActiveRecord
{
/**
* The followings are the available columns in table 'feature':
* #var integer $id
* #var integer $feature_name_id
* #var string $display_name
* #var integer $language_id
* #var string $long_blurb
* #var string $short_blurb
* #var string $subhead_text
* #var string $hero_img
* #var string $mobile_hero_img
* #var string $thumb_sm
* #var string $thumb_md
* #var string $thumb_lg
* #var string $link_url
* #var string $link_image
* #var string $link_text
* #var string $buyit_id
* #var string $seo_text
* #var string $meta_description
* #var string $meta_keywords
* #var integer $category_id
* #var integer $sub_cat_id
* #var string $deep_link
* #var string $tracking_id
* #var integer $weight
* #var integer $initial_rating
* #var string $active
* #var string $created
* #var string $modified
*/
/**
* Returns the static model of the specified AR class.
* #return CActiveRecord the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
/**
* #return string the associated database table name
*/
public function tableName()
{
return 'feature';
}
/**
* #return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('feature_name_id', 'required'),
array('feature_name_id, language_id, category_id, sub_cat_id, weight, initial_rating', 'numerical', 'integerOnly'=>true),
array('active', 'length', 'max'=>1),
array('display_name, long_blurb, short_blurb, subhead_text, page_title, hero_img, mobile_hero_img, thumb_sm, thumb_md, thumb_lg, link_url, link_image, link_text, buyit_id, seo_text, meta_description, meta_keywords, deep_link, tracking_id, created', 'safe'),
);
}
/**
* #return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
// 'VarName'=>array('RelationType', 'ClassName', 'ForeignKey', ...additional options)
return array(
'feature_name' => array(self::BELONGS_TO, 'feature_name', 'feature_name_id', 'alias'=>'feature_name'),
'language' => array(self::BELONGS_TO, 'language', 'language_id', 'on'=>'t.language_id = language.id', 'alias'=>'language'),
'category' => array(self::BELONGS_TO, 'category', 'category_id', 'alias'=>'category'),
'sub_cat' => array(self::BELONGS_TO, 'sub_cat', 'sub_cat_id'),
'language_r' => array(self::BELONGS_TO, 'language', 'language_id', 'alias'=>'language'),
);
}
/**
* #return array Named Scopes.
*/
public function scopes()
{
return array(
'active'=>array(
'condition' => 't.active="y"',
'order' => 'feature_name.type_id DESC, category_id, sub_cat_id, t.weight ASC',
),
);
}
/**
* #return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id' => 'Id',
'feature_name_id' => 'Feature Name ID',
'display_name' => 'Display Name',
'language_id' => 'Language',
'long_blurb' => 'Main Description',
'short_blurb' => 'Short Blurb',
'subhead_text' => 'Subhead Text',
'page_title' => 'Browser Title',
'hero_img' => 'Hero Img',
'mobile_hero_img' => 'Mobile Hero Img',
'thumb_sm' => 'Small Thumbnail',
'thumb_md' => 'Medium Thumbnail ',
'thumb_lg' => 'Large Thumbnail',
'link_url' => 'CTA Link Url',
'link_image' => 'CTA Link Image',
'link_text' => ' CTA Link Text',
'buyit_id' => ' BuyIt Link Product ID',
'seo_text' => 'SEO Copy',
'meta_description' => 'Meta Description',
'meta_keywords' => 'Meta Keywords',
'category_id' => 'Category',
'sub_cat_id' => 'Sub Category',
'deep_link' => 'Deep Link',
'tracking_id' => 'Tracking ID',
'weight' => 'Weight',
'initial_rating' => 'Initial Rating',
'active' => 'Active',
'created' => 'Created Date',
'modified' => 'Modified Date',
);
}
}
Here is your clue :
#3 /data/www.zoomiezoom.com/protected/views/feature/_form.php(74): CHtml::activeTextField(Object(feature), 'mobile_hero_img', Array)
You are pointing to a field in your feature model that does not exist.
It's there in the model. Is is in the feature table, and are you pointing to the correct model in the form.
I am guessing that you are trying to access a property of a model which extends CActiveRecord.
This means that:
Either you HAD defined this property (mobile_hero_img) and now it is removed
OR
You changed the database schema by dropping a column (mobile_hero_img) from a table (the table that your model class relates to).
It looks like an issue from your DB field.
Did you add a new input field "mobile_hero_img" in the form without adding the field it to the database? Please provide the schema of your "feature" table.
For everyone struggling with "Property is not defined" issue I have one suggestion: check your model's rules() definition and framework's version because there's a bug introduced in Yii (1.1.16) which leads to this error if there is additional space at the end of attributes' list:
// author_id WILL NOT WORK!!
array('app_id, group_id, author_id ', 'required'),
This is fixed in Yii 1.1.17.
The "Property n is not defined" issue can also occur if you have set (text) type of a field and in your model while defining a property, you may have defined it as a boolean or integer.
For example, the below is wrong for text type property.
* #property boolean $billing_address
The right definition will be
* #property string $billing_address
Sometimes there is a small mistake that takes hours to be traced.
I had a same issue. Everything was perfect in the Model class but the problem is still on. Restart the server or SQL does not help. At last, I clear the protected/runtime/cachexxxx.db file, then everything working fine.
I modified the tables with migrate file, and sometimes got error so maybe something is mixed.
My problem was solved when I upgraded to yii 1.1.17
Regards

Categories