What is the correct place to set the Default Namespace for a Multiple Module project created with Phalcon DevTools? - phalcon

I just started looking about Phalcon this week, I'm trying to create a multiple module application with the dev tools.
The result of running phalcon project <name> multiple only creates one module ('frontend') and it works fine. However, when I add a second module (by copying the frontend one and changing the namespace to \Backend , I couldn't get to the Backend\IndexController class.
After reading the doc page about mutiple module applications and looking at the samples (https://github.com/phalcon/mvc/tree/master/multiple and https://github.com/phalcon/mvc/tree/master/multiple-volt) and an old question on the Google group (sorry, can't post more than 2 links since I'm new on StackOverflow), I've ended commenting this this line on the services.php file:
$router->setDefaultNamespace("MyL\Frontend\Controllers"); //project name is MyL
and adding the following on the setServices of my backend/Module.php file:
$di->set('dispatcher', function() {
$dispatcher = new Dispatcher();
$dispatcher->setDefaultNamespace("MyL\Backend\Controllers");
return $dispatcher;
});
and the something similar on the frontend/Module.php
It works with these modifications, but my question is: is this the best way to do it, or is there a better way?
Thanks in advance!

You need to register your modules in your app like so:
$app = new \Phalcon\Mvc\Application();
$app->registerModules(
[
'frontend' => [
'className' => 'MyL\Frontend\Controllers',
'path' => '../apps/frontend/Module.php'
],
'backend' => [
'className' => 'MyL\Backend\Controllers',
'path' => '../apps/backend/Module.php'
],
]
);
Make sure that you have the Module.php ready also for each module

Here is a simple way to split frontend and backend in Phalcon project without modules:
https://github.com/borzov/phalcon-templates

Related

TYPO3 10.4 new fields not found in frontend

I have extended database table fe_users with new field using extension builder. The fields are visible in backend user-interface, but not available in frontend in Typo3 10.4.x . But the same code works fine in Typo3 9.x frontend and backend.
I have also tried setting recordType to nothing in the ext_typoscript_setup.typoscript but this also does not help
mapping {
tableName = fe_users
recordType =
}
Any ideas on what more to look for?
The table mapping of the Extbase persistence is not longer possible in TypoScript. Migrate your TypoScript to a PHP file named EXT:myextension/Configuration/Extbase/Persistence/Classes.php.
See breaking change 87623 for further details.
A typical Classes.php file looks like the following.
<?php
return [
\Vendor\Extension\Domain\Model\Object::class => [
'tableName' => 'tx_extension_domain_model_object',
]
];
This is how I implemented it. There was one more line (.i.e 'subclasses') that had to be added to Michael's response. (This is tested in Typo3 11.x as well)
My Configuration/Extbase/Persistence/Classes.php
<?php
declare(strict_types=1);
return [
\TYPO3\CMS\Extbase\Domain\Model\FrontendUser::class => [
'subclasses' => [
'\T3IN\T3inStores\Domain\Model\UserStore' => \T3IN\T3inStores\Domain\Model\UserStore::class,
]
],
\T3IN\T3inStores\Domain\Model\UserStore::class => [
'tableName' => 'fe_users',
'recordType' => 'Tx_T3inStores_UserStore',
],
];
Ref
For every superclass additional all subclasses have to be declared under subclasses
recordType : Look up the TCA of the model to get this value. Or lookup DB after creating a record of that type.

Yii Console Application does not auto-import Model as web appliccation

Here is my console.php which is same as main.php
return array(
'basePath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..',
'name' => 'My Console Application',
// preloading 'log' component
'preload' => array('log'),
// autoloading model and component classes
'import' => array(
'application.models.*',
'application.components.*',
'application.extensions.*',
),
The web application has no problem access those functions. However, console application yields error
Fatal error: Call to undefined method Myfunction::get_all_recipients()
An discussion of this problem is also found at
https://github.com/yiisoft/yii/issues/2344
Also tried suggestions
Yii Command Line Does Not Autoload Models
but it still does not import model classes.
The second solution should work, but sometimes I use another approach. In the console command itself add the following:
Yii::import('application.models.YourModel');
or
Yii::import('application.models.Subfolder.YourModel');
if it's located in subfolder for example;
This should placed before your code is processed. This autoloads only models or classes that your need for current command.

Extending Laravel 5.1 Mess Detection the right way

Laravel 5.1 has only one built-in hardcoded Mess Detection, it searches to see if #package tag is the same with /namespace, like so:
preg_match('/namespace\ ' . self::REQUIRED_NAMESPACE . '\\\(.*);/isU', $content, $namespace);
preg_match('/\/*( )+#package\ (.*)[\r?\n]/isU', $content, $package);
if (!isset($namespace[1]) || empty($namespace[1])) {
continue;
}
I want to extend this to add multiple detection classes.
My folder structure currently looks like this:
Helpers >
Commands >
MessDetector >
Detector >
DetectorInterface.php
DetectorAbstract.php
PackageTagDetector.php
MessDetector.php
The file MessDetector is made as an Artisan Command, that means it extends \Illuminate\Console\Command
I have a config file called mess_detection.php which has the detection rules like so:
return [
'rules' => [
'\Helpers\Commands\MessDetector\PackageTagDetector' =>
[
'rule' => '/\/*( )+#package\ (.*)[\r?\n]/isU',
'path' => app_path(),
'info' => 'Checking for #package tag',
'error'=> 'Malformed or missing package tag'
]
]
];
But got stuck with figuring out how exactly to instantiate PackageTagDetector class in MessDetector class.
Any ideas design pattern wise?
Laravel has no built in mess detector.
Also checking if package tags matches the namespace is a custom convention, Laravel doesn't use package tags at all.
It seems like you are using a third party library?
I have made an abstract class and interfaces for every rule I needed.
Each rule had it's own class.
The rules extended the abstract and in the abstract most of the logic was used.
The rules themselves where stored in a config file, in the config file I also mentioned the class and class specific actions.

yii-booster set up giving me errors

Sorry real new to yii, but where do i put the yii-booster 2.0 files?
I tried putting all the files into the extensions/bootstrap folder.
I then edited config/main.php and added this
'bootstrap' => array(
'class' => 'bootstrap.components.Bootstrap',
),
and
'preload'=>array(
'log',
// 'fontawesome',
'bootstrap',
),
and
'theme'=>'bootstrap',
where I have a theme in themes/bootstrap which I took from my previous installation of http://www.cniska.net/yii-bootstrap/
but I'm getting this error
Bootstrap and its behaviors do not have a method or closure named "register".
from the theme you got from http://www.cniska.net/yii-bootstrap/
try removing this in themes/bootstrap/views/layout/main.php
Yii::app()->bootstrap->register();

Prevent Yii from loading JS out of assets

Is there a way to configure Yii such that it will no longer load any Javascript out of the Assets folder?
Make your own AssetManager or extend current
protected/components/DummyAssetManager.php:
class DummyAssetManager extends CApplicationComponent {
public function publish(){}
}
add into components array in
protected/config/main.php:
'assetManager'=>array(
'class'=>'DummyAssetManager',
),
You should consult the manual for a detailed description of
the assetManager options
I think you can try following option in your config/main.php
'components' => array(
'assetManager' => array(
'linkAssets' => true,
),
),
This will make asset files symbolic links to your original js/css sources. See linkAssets for more details on it.
If your PHP<5.3, or the OS it's running on doesn't support symbolic links, you won't be able to use 'linkAssets' option, in this case you can try:
'components' => array(
'assetManager' => array(
'forceCopy' => true,
),
),
This should update asset folder on every request. These two options are usually used during development process (btw, you can't use both) and should be removed from production.
PS: if you're sure that you haven't explicitly enabled ckeditor somewhere in your code and you're confident about your assetmanager calls throughout the code, check your layout and page for widgets that require this CKeditor, as Yii can't preload 'stuff' just randomly, it can be triggered by some preloaded component/extension or yii widget.