PHP-activerecord - 'Class \ActivityQuestion does not exist' - codeigniter-2

I have tables
- topics(id, name)
- activities(id, name)
- activities_questions(id, activity_id)
I have 2 models named
Activity.php
class Activity extends ActiveRecord\Model {
static $belongs_to = array(array('topic'));
static $has_many = array(array('activity_question'));
}
-Activities_question.php
class ActivitiesQuestion extends ActiveRecord\Model {
static $table_name = 'activities_questions';
static $belongs_to = array(
array('activity')
);
}
Am I doing something wrong or I am missing something in my model name or file name. I am getting errors something like
Fatal error: Uncaught exception 'ReflectionException' with message 'Class \ActivityQuestion does not exist'
I need help, I am not sure about the correcting.
Thanks.

Related

CS8618 - Non-nullable variable must contain a non-null value when exiting constructor. Consider declaring it as nullable

I got a warning on the main form structure (green line under mainform)
namespace WinFormsApp1
{
public partial class mainForm : Form
{
public mainForm() /* The warning is here */
{
InitializeComponent();
}
How to fix this without changing the project settings?
I don't think this a duplicated question.
Best regards,

Laravel Trying to get property '' of non-object error

I am getting an error. I have shared the necessary code below. When I add kernel code, this error goes away and it works fine, but it causes other errors to not appear. What do you think could be the problem?
class TrendyolController extends Controller
{
public $baseUrl;
public $guzzle;
public $businessId;
public $marketplaceSettings;
public $authentication;
public function __construct()
{
// Set base url
$this->baseUrl = env('TRENDYOL_BASE_URL');
// Set guzzle
$this->guzzle = new Client();
// Set business id
$this->businessId = Session::get('user.business_id');
// Set marketplace settings
$this->marketplaceSettings = Business::find($this->businessId);
// Set authentication
$this->authentication = base64_encode($this->marketplaceSettings
->trendyolExternalKey1 . ':' .
$this->marketplaceSettings->trendyolExternalKey2);
}
}
Error

easyaDmin 3.3 create custom filter

I struggle to understand how i'm supposed to do a custom filter in easyadmin 3.3 . The documentation isnt helping. I alway got an error
Error: Class App\Entity\entity1 has no field or association named "field1"
So i tried to put the mapping as false to prevent this, following the doc and i'm getting this
Attempted to call an undefined method named "mapped" of class "App\Controller\Admin\Filter\customfilter".
here my code :
Crud controller :
public function configureFilters(Filters $filters): Filters
{
return $filters
->add(getAutoclaveFilter::new('fiedWithNoAssociation')->mapped(false))
;
}
custom filter :
class GetAutoclaveFilter implements FilterInterface
{
use FilterTrait;
public static function new(string $propertyName, $label = null): self
{
return (new self())
->setFilterFqcn(__CLASS__)
->setProperty($propertyName)
->setLabel($label);
}
public function apply(QueryBuilder $queryBuilder, FilterDataDto $filterDataDto, ?FieldDto $fieldDto, EntityDto $entityDto): void
{
$queryBuilder->andWhere(sprintf('%s.%s = :value', $filterDataDto->getEntityAlias(), $filterDataDto->getProperty()))
->setParameter('value',$filterDataDto );
}
And the entity :
public function fiedWithNoAssociation()
{
return $this->getEntityAssociated()->getEntity2();
}
What i'm doing wrong ? Is the mapped function not implemented yet ?
Use instead of mapped:
->setFormTypeOption('mapped', false)

Test with Lumen package

I develop lumen package and I don't know test this.
In my package, I use global method config() and abort() but this methods exist with bootstrap/app.php and I have'nt this file in my package.
I'm thinking redefine this methods with dummies class but I have to write only one test method in test class when I test a method with a changement in the config to can re-call an antoher config dummy class .
It's not practical and I guess there's better.
I can share code if you want.
--- Edit
This is example :
Class CheckAuthorizationTest
public function testCanSeeOtherUserRoles()
{
$this->assertTrue(CheckAuthorization::canSeeOtherUserRoles($user, $user));
}
Class CheckAuthorization
static public function canSeeOtherUserRoles(Model $user_parent, Model $user_child)
{
return self::roleIsParentOfDirectChild($user_parent, $user_child);
}
static public function canShowGroup(array $parent_group, string $child_group)
{
$groupsHelper = new GroupsHelper();
foreach ($parent_group as $group) {
if (in_array($child_group, config('roles.roles'))) {
return true;
}
}
abort(403);
}
Result :
There was 1 error:
1) ::testCanSeeOtherUserRoles
ReflectionException: Class config does not exist

How do I create conditional ValidationAttribute error messages?

I have a custom ValidationAttribute in my ASP.NET MVC3 project which has two conditions which need to be met. It works well but I would like to let the user now which validation rule has been broken by returning a customised error message.
With the method I am using (inherit error message from base class) I know I can not change the value of the _defaultError constant after it has been initialised, so....
How do I return different error messages depending on which condition was not met?
Here is my ValidationAttribute code:
public class DateValidationAttribute :ValidationAttribute
{
public DateValidationAttribute()
: base(_defaultError)
{
}
private const string _defaultError = "{0} [here is my generic error message]";
public override bool IsValid(object value)
{
DateTime val = (DateTime)value;
if (val > Convert.ToDateTime("13:30:00 PM"))
{
//This is where I'd like to set the error message
//_defaultError = "{0} can not be after 1:30pm";
return false;
}
else if (DateTime.Now.AddHours(1).Ticks > val.Ticks)
{
//This is where I'd like to set the error message
//_defaultError = "{0} must be at least 1 hour from now";
return false;
}
else
{
return true;
}
}
}
I could advise you to create two different implementation of DateValidator class, each having different message. This is also in line with SRP as you just keep the relevant validation information in each validator separate.
public class AfternoonDateValidationAttribute : ValidationAttribute
{
// Your validation logic and message here
}
public class TimeValidationAttribute : ValidationAttribute
{
// Your validation logic and message here
}

Resources