extending _remap function codeigniter in hooks or MY_Controller - hook

i have a codeigniter application that use HMVC, but for Authentication i have a Controller Auth.php, that i put it in a base Codeigniter Controller Folder not in the module folder of HMVC.
i'm using this remap function only on controller in module folder. In every module controller there is this code.
public function _remap($method) {
$segment = $this->uri->segment(4);
switch ($method) {
case 'view':
if($segment === 'create') {
$this->create_view();
} elseif($segment === 'update') {
$this->update_view();
} else {
$this->search_view();
}
break;
case 'process':
if($segment === 'create') {
$this->create_process();
} elseif($segment === 'update') {
$this->update_process();
} else {
$this->delete_process();
}
break;
default:
$this->main_view();
break;
}
}
the question is, how can i remove this code in every module controller? I'm testing to puth the code using MY_Controller extending MX_Controller. Is Working, but in my Auth.php that extending CI_Controller is error. I have been testing using hooks, but with no luck. Is there a way to do that?

already find the answer! Just chance MY_Controller name into something else and it works.

Related

Extended fe_user model, can't access crdate when run via cronjob

I have a problem with accessing the crdate of a fe_user in a croniob task. I have an extended Frontend user model where I added this adjustments:
https://stackoverflow.com/a/50663006/1684975
Additionaly I've added a mapping via ts
config.tx_extbase {
persistence {
classes {
TYPO3\CMS\Extbase\Domain\Model\FrontendUser {
subclasses {
Tx_MyExt_User = ACV\MyExt\Domain\Model\User
}
}
Paul\MyExt\Domain\Model\User {
mapping {
tableName = fe_users
recordType = Tx_MyExt_User
columns {
crdate.mapOnProperty = crdate
}
}
}
}
}
}
When I fire up the Scheduler task manual via the Scheduler BE module it's ok. But when the real cronjob kicks in I get the error
Uncaught TYPO3 Exception Call to a member function getTimestamp() on null
In the Scheduler task, I get the crDate via the getter and try to get the timestamp…
$users = $frontendRepository->findByOptIn(false);
foreach ($users as $user) {
if ($user->getCrdate()->getTimestamp() < strtotime('-5 days')) {
$frontendRepository->remove($user);
}
}
The mode of the user is correct. I can access other custom properties I've added to the model.
It's TYPO3 v9.5.26.
The odd thing is that it runs locally in my dev environment.
Did someone have an idea what could cause the problem?
Add a file <extensionfolder>/ext_typoscript_setup.typoscript and add your TypoScript in there:
config.tx_extbase {
persistence {
classes {
TYPO3\CMS\Extbase\Domain\Model\FrontendUser {
subclasses {
Tx_MyExt_User = ACV\MyExt\Domain\Model\User
}
}
Paul\MyExt\Domain\Model\User {
mapping {
tableName = fe_users
recordType = Tx_MyExt_User
columns {
crdate.mapOnProperty = crdate
}
}
}
}
}
}
Alternativly you can add an include there to your TypoScript file in your extension Configuration/TypoScript folder.
If you are in CLI Context, it can be that the TypoScript is not loaded fully for the mapping/extbase configuration, which would match your description that in the BE Context it works, but not in Cronjob/CLI Context.

Shopware 6: Extend existing core DAL entities with a reference

I'm trying to create a connection between 2 existing entities PropertyGroup and CustomFieldSet. Use-case is irrelevant.
So I created an EntityExtension:
public function extendFields(FieldCollection $collection): void
{
$collection->add(
(new ManyToOneAssociationField('customFieldSet', 'custom_field_set', CustomFieldSetDefinition::class))
);
}
public function getDefinitionClass(): string
{
return PropertyGroupDefinition::class;
}
And override the administration component to also include this association when loading the entity:
Component.override('sw-property-detail', {
methods: {
loadEntityData() {
this.isLoading = true;
const criteria = this.defaultCriteria;
criteria.addAssociation('customFieldSet', new Criteria(1, 500));
this.propertyRepository.get(this.groupId, Shopware.Context.api, criteria)
.then((currentGroup) => {
this.propertyGroup = currentGroup;
this.isLoading = false;
}).catch(() => {
this.isLoading = false;
});
}
}
});
(I tried to override defaultCriteria but that didn't work because of this.$super being unable to access computed properties).
But it keeps saying FRAMEWORK__ASSOCIATION_NOT_FOUND. I debugged the EntityDefinition and it seems that this extension is not even loaded.
I checked if my EntityExtension is loaded in the Symfony container and it is, but it seems that it doesn't reach the entity definition.
The EntityExtension seems to be missing the addition of a FkField inside the function extendFields:
public function extendFields(FieldCollection $collection): void
{
$collection->add(
(new FkField('custom_field_set', 'customFieldSetId', CustomFieldSetDefinition::class)),
);
$collection->add(
(new ManyToOneAssociationField('customFieldSet', 'custom_field_set', CustomFieldSetDefinition::class))
);
}
A new use statement has to be added for the FkField:
use Shopware\Core\Framework\DataAbstractionLayer\Field\FkField;

Can I call NavigationManager in a Blazor service

I am trying to create an error page service which, when called, will determine which type of exception has occurred and processes the code properly. If the exception is of type "redirect", it should send the user to a login page (for testing purposes, I'm just using the home "/" page).
I'm trying to use NavigationMangager.NavigateTo("/") but am running into a Null point exception whenever I reach that function call. I've been looking for a solution to this for a while now but everything I see is usage of NavigationManager in .razor files and I'm trying to complete this within a .cs service. Is this not possible currently or am I just doing something wrong? I've included all the relevant code from my file "ErrorProcessingService.cs" below, any help would be appreciated.
using ToDoList.Pages;
using Microsoft.AspNetCore.Components;
namespace ToDoList.ExceptionHandler
{
public class ErrorProcessingService
{
[Inject]
protected NavigationManager NavigationManager {get; set;}
public void processError(ErrorTypes.errorType et)
{
new ErrorTypes();
switch(et)
{
case ErrorTypes.errorType.ignore:
//To Be Implemented
break;
case ErrorTypes.errorType.popup:
//To Be Implemented
break;
case ErrorTypes.errorType.redirect:
NavigationManager.NavigateTo("/");
break;
}
}
}
}
In a service you cannot use [Inject] attribute but inject dependency in constructor:
using ToDoList.Pages;
using Microsoft.AspNetCore.Components;
namespace ToDoList.ExceptionHandler
{
public class ErrorProcessingService
{
public ErrorProcessingService(NavigationManager navigationManager)
{
NavigationManager = navigationManager;
}
protected NavigationManager NavigationManager { get; }
public void processError(ErrorTypes.errorType et)
{
new ErrorTypes();
switch(et)
{
case ErrorTypes.errorType.ignore:
//To Be Implemented
break;
case ErrorTypes.errorType.popup:
//To Be Implemented
break;
case ErrorTypes.errorType.redirect:
NavigationManager.NavigateTo("/");
break;
}
}
}
}

geb.page content module cannot be resolved

Hi i tried to do a NavigationModule to acces to my content in geb.page, but when i want to instance from this navigation 'module' cannot be resolved by intellij
class NavigationModule extends Module{
static content = {
homeLink { $("a", title:"Home") }
contactLink { $("a", title:"Contact Us") }
}
}
class HomePage extends Page{
static url = "http://www.websitetest.com"
static at={
assert $("h1").text() == "Test website speed and performance"
}
static content = {
navBar {module NavigationModule}
//loginLink { $("a", text: "login")[0]}
}
}
and also I can't access from my script
void test() {
Browser.drive() {
to HomePage
navBar.
}
}
someone know what happen? I spent a lot of time searching in google but i don't find anything
thanks in advance
The Geb doc (http://www.gebish.org/manual/current/ide-and-typing.html#strong_typing) recommends to expecitly define Types to have a better IDE support.
With this example code completion works for me.
class HomePage extends Page {
static url = "http://www.websitetest.com"
static at={
assert $("h1").text() == "Test website speed and performance"
}
static content = {
navBar {module NavigationModule}
//loginLink { $("a", text: "login")[0]}
}
// explicitly define getter to give IntelliJ more type information
NavigationModule getNav() {
navBar
}
}
Test script:
void test() {
Browser.drive() {
// assign to page in order to have code completion on page
page = to HomePage
// code completin for homeLink works
navBar.homeLink
}
}

How can I get this old Ninject 2 code to work with Ninject 3 and the MVC 2 extension (NinjectControllerFactory)?

In my MVC 2 project, I originally used Ninject 2 and wrote this version of the NinjectControllerFactory:
public class NinjectControllerFactory : DefaultControllerFactory
{
private IKernel kernel = new StandardKernel(new HandiGamerServices());
protected override IController GetControllerInstance(System.Web.Routing.RequestContext requestContext, Type controllerType)
{
try
{
if (controllerType == null)
{
return base.GetControllerInstance(requestContext, controllerType);
// return null;
}
}
catch (HttpException ex)
{
if (ex.GetHttpCode() == 404)
{
IController errorController = kernel.Get<ErrorController>();
((ErrorController)errorController).InvokeHttp404(requestContext.HttpContext);
return errorController;
}
else
{
throw ex;
}
}
return (IController)kernel.Get(controllerType);
}
Of most importance is the retrieval of my ErrorController, which allows me to gracefully handle a multitude of HTTP errors.
The problem is that I upgraded to the MVC 2 extension via Nuget, so a NinjectControllerFactory is already provided. Would it be possible to use my own override of GetControllerInstance? If so, how?
I do exactly this, and for precisely the same reason. In Global.asax.cs, I add this to my OnApplicationStarted override (declared virtual in NinjectHttpApplication):
ControllerBuilder.Current.SetControllerFactory(
new MyControllerFactory(ControllerBuilder.Current.GetControllerFactory()));
This means you're creating your own controller factory, but providing it with the default implementation to do the heavy lifting.
Then define your controller factory like so:
public class MyControllerFactory : IControllerFactory
{
private IControllerFactory defaultFactory;
public MyControllerFactory(IControllerFactory defaultFactory)
{
this.defaultFactory = defaultFactory;
}
public IController CreateController(RequestContext requestContext, string controllerName)
{
try
{
var controller = defaultFactory.CreateController(requestContext, controllerName);
return controller;
}
catch (HttpException e)
{
// Pasted in your exception handling code here:
if (ex.GetHttpCode() == 404)
{
IController errorController = kernel.Get<ErrorController>();
((ErrorController)errorController).InvokeHttp404(requestContext.HttpContext);
return errorController;
}
else
{
throw ex;
}
}
}
public SessionStateBehavior GetControllerSessionBehavior(RequestContext requestContext, string controllerName)
{
return defaultFactory.GetControllerSessionBehavior(requestContext, controllerName);
}
public void ReleaseController(IController controller)
{
defaultFactory.ReleaseController(controller);
}
}
As you can see, we're just using the default (Ninject) controller factory for most purposes unless it can't find the page. For obtaining the error controller, you can either pass in the kernel as you were already doing, or just call defaultFactory.CreateController using the error controller name.

Resources