Not sure if Smarty is even loading but its showing {$title} and {$username} directly on the page and not using what's set as the variable.
I added into composer.json
"smarty/smarty": "*"
I run php composer.phar update and also install:
I'm loading in the config.php file the parser as per
'packages' => array(
'orm',
'auth',
'parser',
),
In my controller dashboard.php
public function action_index()
{
$data = [
'bodyclass' => "dashboard",
'title' => "Dashboard",
'username' => "James"
];
$view = Response::forge(View::forge('dashboard/index.tpl', $data));
$this->template->subnav = array('dashboard'=> 'active' );
$this->template->content = $view;
}
and in my index.tpl file I have
{$title} {$username}
It's just for testing, however does not seem to be working.
FuelPHP's Parser package handles the rendering of views using template engines.
As you've already done, you must first enable the Parser package in fuel/app/config.php by making sure the parser package is added to always_load
'always_load' => array(
'packages' => array(
'parser',
),
),
Parser uses the file's extension to determine which parser engine to use. In your case your file, dashboard/index.tpl uses a typical smarty extension .tpl, however FuelPHP doesn't have a template registered for that extension.
FuelPHP uses .smarty by default.
So, you have 2 options.
Change your template's file extension, adhering to the FuelPHP default
Change FuelPHP's configuration to use Smarty for .tpl files
Fortunately both are easy. If you choose to go with option 2, check out the default configuration definition.
You can override the defaults using a config file located at fuel/app/config/parser.php
return array(
// Overrides default smarty extension
'extensions' => array(
'tpl' => 'View_Smarty',
)
);
Related
how I can load an external-site module? I have a common module I need to load in distinct Yii2 sites, like advanced-template my idea is to have a common dir where store generic modules wich I can load to each site. A file system structure can be like this:
/
site-1/
(loads modules from common-modules dir for site-1)
site-2/
(loads modules from common-modules dir for site-2)
common_sites_modules/
module-1/
module-2/
carrello/
Carrello.php
Each site in his configuration have to load modules from common-modules/
Is possible to implement this structure?
Edit 1
The configuration:
'cart' => [
'class' => dirname(dirname(dirname(__DIR__))) . '/common_sites_modules/carrello/Carrello',
'params' =>[
...
],
'components' => [
...
],
],
and this is the first line of the class Carrello.php:
<?php
namespace common_sites_modules\carrello;
...
The top bar of editor with the path of the class and the error returned by Yii:
Edit 2:
Thanks to #Yupik for support and suggests, the new settings:
bootstrap.php:
Yii::setAlias('#common-modules', dirname(dirname(dirname(__DIR__))) . '/common_sites_modules');
main-local.php:
'class' => '#common-modules\carrello\Carrello',
The generated error:
Like suggested in the comments the solution is to declare an alias and then use the name of alias for call the module. Like suggested by #Yupik I've set in the common/config/bootstrap.php an alias as follow:
Yii::setAlias('#common_modules', dirname(dirname(dirname(__DIR__))) . '/common_modules');
In the main configuration:
'carrello' => [
'class' => ''common_modules\carrello\Carrello',
...
]
Obviously namespace have to be configured based on the position on filesystem.
Thanks for the suggestions
Yes, we can do this by making a symlink of common_sites_modules directory in both site folder (site1, site2).
I'm trying to write a test for a module that requires a specific configuration change during a test run, overwriting the default configuration provided by the module's own module.config.php.
In a normal application run, configuration is merged in order and I can use config/autoload/*.local.php to supersede module's config. But during a phpunit run those files aren't loaded, and I can't find a way to modify it during testing runtime.
I tried modifying the config in my Bootstrap file, to no avail; and even in the test controller setup directly:
public function setUp()
{
$app_config = include(Bootstrap::getRootPath() . '/config/application.config.php');
$test_config = Bootstrap::getTestConfig();
$new_config = ArrayUtils::merge($app_config, $test_config);
$this->setApplicationConfig($new_config);
}
But by the time one of the factories is running I check the values for the config during a debug session, and my injected values are nowhere to be found.
Also tried hooking to EVENT_MERGE_CONFIG and modify it there:
public static function onMergeConfig(ModuleEvent $e)
{
$configListener = $e->getConfigListener();
$config = $configListener->getMergedConfig(false);
$new_config = ArrayUtils::merge($config, $this->getTestConfig(static::$zf2ModulePaths));
// Pass the changed configuration back to the listener:
$configListener->setMergedConfig($new_config);
}
What's the proper way to accomplish this?
Personally I go with a similar approach as zfcampus/zf-development-mode does. Depending on the environment, I add another config_glob_paths to the application configuration. While I use it for managing development related configuration, this can easily be adapted for testing.
The basic idea is to have two application configuration files, one general and one environment specific (expect for production).
application.config.php:
return [
'modules' => [],
'module_listener_options' => [
'config_glob_paths' => [
__DIR__ . '/autoload/{{,*.}global,{,*.}local}.php',
],
'config_cache_enabled' => false,
'module_map_cache_enabled' => false,
],
];
development.config.php:
return [
'modules' => [],
'module_listener_options' => [
'config_glob_paths' => [
'config/autoload/{,*.}{global,local}-development.php',
],
'config_cache_enabled' => false,
'module_map_cache_enabled' => false,
],
];
Merging those two, will autoload the files matching in this order:
'config_glob_paths' => [
__DIR__ . '/autoload/{{,*.}global,{,*.}local}.php',
'config/autoload/{,*.}{global,local}-development.php',
],
While the later ones (postfixed with -development) will overwrite settings of the default ones.
So in my autoload directory I have the files like:
database.global.php
database.global-development.php
Local files are still possible for each environment as well of course:
database.local.php
database.local-development.php
The load order on development for the files then would be (if existing):
database.global.php
database.local.php
database.global-development.php
database.local-development.php
On a production environment, the development.config.php file is not merged, hence the *-development.php files are not loaded.
This pattern can easily be changed to testing environments as well of course. It is also noteworth that by this approach, you can change other application settings as well (e.g. application config caching / modules to load).
I want to make my own module in zend framework2, I have tried this below code as per the doc. mentioned
return array(
'modules' => array(
'Application',
'Album',
'Photo',
'SanAuth',
'Newmodule', // <- here is my newly added module name
),
'module_listener_options' => array(
'config_glob_paths' => array(
'config/autoload/{,*.}{global,local}.php',
),
'module_paths' => array(
'./module',
'./vendor',
),
),
);
But when I add this only one line code! my all working module gives blank result even which are working fine started giving blank result!
How can I come out from this ?
What you did is enabling the Module. You should have created it first.
Take a look here.
And you can use ZFTool for module managing (it saves you from the dull process).
It's normal to see a blank screen. There is an Exception being thrown which is probably saying that your module doesn't exist or something like that. Make sure you set display_errors = On in your php.ini, so you can debug in an easier manner.
All you have done it tell Zend to start looking for a new module, but you have yet to create the module.
to create the module you need to add a folder with the same name under the ./module folder.
namespace ModuleName;
Class Module {
}
which is the minimum a module needs to load.
I've created a multimodule application using phalconphp developer tool:
phalcon project <projectname> module
And I've added a backend module (the frontend is generated). Now I would like all backend routing do the following:
$route->add('/admin/:controller/:action/:param', array(
'module' => 'backend',
'controller' => 1,
'action' => 2,
'params' => 3,
));
But my routing also defines:
$router->setDefaultModule("frontend");
$router->setDefaultNamespace("Groendesign\Backend\Controllers");
And therefor when I browse to: http://myprojectname/admin it searches in my backend module for the frontend Namespaces, How should I proceed with this?
What I want to achieve is that every url that has the prefix /admin/ is send to the backend module. Using the url to define which controller, action and parameters.
I've fixed this by removing the setDefaultNamespace from my bootstrap and adding it to the Modules.php file in each Module. Thereby setting the DefaultNamespace only in the correct module.
Using the config.php always_load configuration, how does one load a language file from a package?
All of the fuelphp documentation alludes to being able to do this, but only shows the syntax for loading from a module.
Here's what I'm trying to do:
fuel/app/config/config.php
'always_load' => [
'language' => [
// loads fuel/app/lang/en/login.php into login group
'login',
],
],
fuel/app/config/production/config.php
'always_load' => [
'language' => [
// override /config/config.php with contents from
// /fuel/packages/pkg/lang/en/login.php
'lang_file_from_package' => 'login',
],
],
Packages are core extensions, which means it will merge the contents of the files found in app and in the package.
As such, there is no method to define you want to load it from the package only, other then by specifying a fully qualified pathname, which will always load just that file.