rendering layout on the production server - zend-framework

My productionserver is not able to render my loginlayout. On my development system everything works fine.
Here comes the error on the production website:
Fatal error: Uncaught Zend\View\Exception\RuntimeException: Zend\View\Renderer\PhpRenderer::render: Unable to render template "layout/layoutlogin"
How I did this:
My Application/config/module.config.php gives the templates as follows:
'view_manager' => [
'display_not_found_reason' => true,
'display_exceptions' => true,
'doctype' => 'HTML5',
'not_found_template' => 'error/404',
'exception_template' => 'error/index',
'template_map' => [
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
'layout/layoutlogin' => __DIR__ . '/../view/layout/layoutlogin.phtml',
'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
],
'template_path_stack' => [
__DIR__ . '/../view',
],
],
In my Indexcontroller I set the Layout to:
$this->layout()->setTemplate('layout/layoutlogin');
That might do what I want!? I get no error and no warning in the development mode on the development environment. Any ideas appreciated!

You may try this way
public function loginAction()
{
// Provide the layout here
$this->layout('layout/layoutlogin');
$view = new ViewModel();
// Here you may set the template
$view->setTemplate("/module/controller/template");
return $view;
}
This actually means you are using a layout which is other than the default and then inside this layout you may use template that you want for this.

The error ist solved. Actually it was a server configuration issue. In this case it was that Apache didn't have enough rights for the folder
data/cache

Related

Zend Framework 3 skeleton two module

I'm following the zend framework 3 skeleton tutorial to the book.
I first got the application module working where it shows the standard welcome to zend screen.
When I added the album module everything went fine. When I navigate to /album in my url it displays the album section so all good there. However, when I remove the /album from the end of the url to get back to the application section I get the following 404 page.
**A 404 error occurred**
Page not found.
The requested controller could not be mapped to an existing controller class.
Controller:
ApplicationController (resolves to invalid controller class or alias:
ApplicationController)
No Exception available
I would show some sections of my code but at the minute I'm unsure as to what file could be causing this. If someone could tell me what config file is causing this issue then I can upload it. I'm pretty sure it's routing but coming from ZF1 it's a bit of a head scratcher.
If someone could help or explain to me where to look I would be very thankful.
UPDATE
Below is my module.config.php for my Application module.
<?php
/**
* #link http://github.com/zendframework/ZendAlbumApplication for the canonical source repository
* #copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* #license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace Application;
use Zend\Router\Http\Literal;
use Zend\Router\Http\Segment;
use Zend\ServiceManager\Factory\InvokableFactory;
return [
'router' => [
'routes' => [
'home' => [
'type' => Literal::class,
'options' => [
'route' => '/',
'defaults' => [
'controller' => \ApplicationController::class,
'action' => 'index',
],
],
],
'application' => [
'type' => Segment::class,
'options' => [
'route' => '/application[/:action]',
'defaults' => [
'controller' => Controller\IndexController::class,
'action' => 'index',
],
],
],
],
],
'controllers' => [
'factories' => [
Controller\IndexController::class => InvokableFactory::class,
],
],
'view_manager' => [
'display_not_found_reason' => true,
'display_exceptions' => true,
'doctype' => 'HTML5',
'not_found_template' => 'error/404',
'exception_template' => 'error/index',
'template_map' => [
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
],
'template_path_stack' => [
__DIR__ . '/../view',
],
],
];
?>
UPDATE 2
When I replace the /album with /application in the url it shows the skeleton zend framework welcome page. I thought this page would show with just http://localhost? Am I missing the point or can I make the application module the default module so you don't have to add /application to the end of the url?
I've done it. It seems like it was a newby mistake/typo.
I had to change the line:
'controller' => \ApplicationController::class,
TO
'controller' => Controller\IndexController::class,
Thank you for pointing me in the right direction and telling me what page of code to upload.

URL-Manager will not route

I cloned our repositorie and created excatly the same URL-rules like at my own project. Now, i will get error like this after having logged in:
Firefox:
Fehler: Umleitungsfehler
The website called is rerouting request,which never will come to an end.
This problem sometimes occures, if cookies are deactivated
Chrome:
ERR_TOO_MANY_REDIRECTS
I definetly accepted using cookies at both browser!!
Debugging shows me,that I have dozen of 302-Requests,so Yii breaks down!
I use Windows, not LINUX, so I don't care about any permissions.
Here are the rules:
'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'showScriptName' => true,
'enableStrictParsing' => true,
'rules' => [
'/' => 'site/login',
'home' => 'site/index',
'logout' => 'site/logout',
'contact' => 'site/contact',
'signup' => 'site/signup',
'reset' => 'site/request-password-reset',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<action:(contact|captcha)>' => 'site/<action>'
],
Here is frontend configuration:
<?php
$config = [
// LZA 17-07-30
'sourceLanguage' => 'de-DE',
'language' => 'de-DE',
// LZA 17-07-30 siehe Funktionen in http://demos.krajee.com/grid#module
'components' => [
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => '4lD2RxDNkC4ckpwxTmkDzOLIvk0JMs3F',
],
],
];
if (!YII_ENV_TEST) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'yii\debug\Module',
];
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
// LZA 17-07-30 CRUD
'generators' => [// customized CRUD generator
'crud' => [
// 'class' => 'app\myCrud\crud\Generator', // LZA 17-07-20 die Klasse von CRUD generator
'class' => '\common\wsl_dev\wsl_crud\crud\Generator', // LZA 17-07-20 die Klasse von CRUD generator
'templates' => [
'myCrud' => '/#common/wsl_dev/wsl_crud/crud/default', //LZA 17-07-20 Templatename und Templatepfad
]
]
],
// LZA 17-07-30 CRUD
];
}
return $config;
If I deacitvate URLManger,setting
'enablePrettyUrl' => false,
everything works fine.
If I put in manually Url like this:
http://localhost/yii2_perswitch/frontend/web/yiic.php/home
everything works fine,too
Any ideas,how to fix this?
I deleted all my cookies,without any effects!
Solution 1:
Enable debug mode from web/index.php (uncomment these two lines):
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');
and you can see exactly what causes the problem.
Redirected too many times error was because the 777 permissions for
runtime and assets folder were not set.
Solution 2:
I think that the problem is related with the path or domain of the cookie. I believe that this info could be useful.
https://github.com/samdark/yii2-cookbook/blob/master/book/cookies.md

Yii2 restful not working

By using this link I tried to have a restful app, but it's not working and always returned this:
Object not found!
The requested URL was not found on this server. If you entered the URL manually please > > check your spelling and try again.
If you think this is a server error, please contact the webmaster.
Error 404
localhost
Apache/2.4.4 (Win32) OpenSSL/1.0.1e PHP/5.5.1
I call it like this: localhost/restful/web/users
Edit:
This kind of call is not working either: localhost/restful/web/?r=users
It returned this:
Not Found (#404)
Page not found.
The above error occurred while the Web server was processing your request.
Please contact us if you think this is a server error. Thank you.
Have the same error (stil getting 404 Not found on each request) have solve it adding .htaccess to (my yii path)/web folder (the same where you have index.php):
# use mod_rewrite for pretty URL support
RewriteEngine on
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
This is because when you create an clean instance of Yii2 you don't have the .htaccess file (in my opinion probably the security reason).
for me the: (enabling curl and using it in my controller) installed via composer
composer require --prefer-dist linslin/yii2-curl "*"
use in controller
<?php
namespace app\controllers;
use yii\rest\ActiveController;
use linslin\yii2\curl;//this was added
class UserController extends ActiveController
{
Don't work.
Maybe this helps someone :)
This is my config/web.php:
<?php
$params = require(__DIR__ . '/params.php');
$config = [
'id' => 'basic',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'components' => [
'urlManager'=>[
'enablePrettyUrl' => true,
'enableStrictParsing' => true,
'showScriptName' => false,
'rules' => [
['class' => 'yii\rest\UrlRule', 'controller' => 'user'],
],
],
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => 'a',
'parsers' => [
'application/json' => 'yii\web\JsonParser',
],
],
'cache' => [
'class' => 'yii\caching\FileCache',
],
'user' => [
'identityClass' => 'app\models\User',
'enableAutoLogin' => true,
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => true,
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'db' => require(__DIR__ . '/db.php'),
],
'params' => $params,
];
if (YII_ENV_DEV) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = 'yii\debug\Module';
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = 'yii\gii\Module';
}
return $config;
And the controller:
<?php
namespace app\controllers;
use yii\rest\ActiveController;
class UserController extends ActiveController{
public $modelClass = 'app\models\User';
}
Also a created my model by gii.
The problem solved by enabling curl and using it in my controller.

ZendFramework2 - Literal- or Segment-Routing and Parameters

I am using ZendFramework 2.x and trying to add a route to some existing ones. Moreover I want to put some parameters in die URL as well. If I use the segment-type for my new route ('showroom') I am able to call my new URL and will get forwarded to the corresponding view. Unfortunately I am not able to set some parameters in the URL. The other option is to use segment type in my module.config.php-file, but I will get some ZF-2-Exception, that my route is not configured correctly, this happens even before rendering my intro-view. Thanks in advance for showing me, how to combine segment and literal-type usage in route-child-route-combination or for telling me how to add parameters to literal type URLs.
Route-configuration in module.config.php of Module:
'router' => array(
'routes' => array(
'zfcuser' => array(
'type' => 'Literal',
'priority' => 1000,
'options' => array(
'route' => '/user',
'defaults' => array(
'controller' => 'zfcuser',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'showroom' => array(
'type' => 'Segment',
'options' => array(
'route' => '/:id',
'defaults' => array(
'controller' => 'zfcuser',
'action' => 'showRoom',
'id' => '1',
),
),
),
'login' => array(
'type' => 'Literal',
UPDATE: snippet which triggers the error (see comments)
<?php
$roomIndex = 1;
foreach($roomsPaginator->getCurrentItems() as $room){
$roomURL = 'zfcuser/showroom' . '/' . $roomIndex;
echo "<p>Name: " . $room['name'] . "; Luftfeuchtigkeit: " . $room['humidity'] . "; <a class='btn' href='" . $this->url($roomURL) . "'>Betreten »</a></p>";
$roomIndex++;
}
?>
I'm not sure if this is the cause of your error, but I don't think you're using the URL helper correctly. You don't build a URL and pass it to the helper, the idea is the helper builds the URL for you using the route name and params. You probably want something like this:
$roomIndex = 1;
foreach($roomsPaginator->getCurrentItems() as $room){
echo "<p>Name: " . $room['name'] . "; Luftfeuchtigkeit: " . $room['humidity'] . "; <a class='btn' href='" . $this->url('showroom', array('id' => $roomIndex)) . "'>Betreten »</a></p>";
$roomIndex++;
}

TYPO3 6.0.4 default controller for extension not found

I created my third extension with the extension builder but this one won't install itself properly. I get the error:
The default controller for extension "NtImpressions" and plugin
"Gallery" can not be determined. Please check for
TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin() in your
ext_localconf.php.
I did not modify anything in the extension files. The Plugin is completly generated by the extension builder. This is the ext_localconf.php
<?php
if (!defined('TYPO3_MODE')) {
die ('Access denied.');
}
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'Xxx.' . $_EXTKEY,
'Gallery',
array(
'Galerie' => 'list, show',
),
array(
'Galerie' => '',
)
);
?>
And the ext_tables.php
<?php
if (!defined('TYPO3_MODE')) {
die ('Access denied.');
}
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
$_EXTKEY,
'Gallery',
'Galerie'
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile($_EXTKEY, 'Configuration/TypoScript', 'Impressionen');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addLLrefForTCAdescr('tx_ntimpressions_domain_model_galerie', 'EXT:nt_impressions/Resources/Private/Language/locallang_csh_tx_ntimpressions_domain_model_galerie.xlf');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages('tx_ntimpressions_domain_model_galerie');
$TCA['tx_ntimpressions_domain_model_galerie'] = array(
'ctrl' => array(
'title' => 'LLL:EXT:nt_impressions/Resources/Private/Language/locallang_db.xlf:tx_ntimpressions_domain_model_galerie',
'label' => 'bezeichnung',
'tstamp' => 'tstamp',
'crdate' => 'crdate',
'cruser_id' => 'cruser_id',
'dividers2tabs' => TRUE,
'versioningWS' => 2,
'versioning_followPages' => TRUE,
'origUid' => 't3_origuid',
'languageField' => 'sys_language_uid',
'transOrigPointerField' => 'l10n_parent',
'transOrigDiffSourceField' => 'l10n_diffsource',
'delete' => 'deleted',
'enablecolumns' => array(
'disabled' => 'hidden',
'starttime' => 'starttime',
'endtime' => 'endtime',
),
'searchFields' => 'bezeichnung,beschreibung,bilder,bilder_beschreibung,',
'dynamicConfigFile' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($_EXTKEY) . 'Configuration/TCA/Galerie.php',
'iconfile' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath($_EXTKEY) . 'Resources/Public/Icons/tx_ntimpressions_domain_model_galerie.gif'
),
);
?>
I guess the namespace is not set correct and TYPO3 is unable to determine your controller GalerieController->listAction.
The first part of the configurePlugin registers the namespace in TYPO3 6.0, so you need to add this namespace to all classes. The Namespace is parsed to the path where the file with the class can be found. This is the equivalent to the old syntax.
Old syntax:
class Tx_YourExtension_Controller_YourController {
//...
}
is now
<?php
namespace YourVendor\YourExtension\Controller;
class YourController {
//...
}
So following configuration
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'Xxx.' . $_EXTKEY,
...
registers Xxx as Vendor, so all your classes need to be in that namespace
<?php
namespace Xxx\Gallery\Controller
class GalleryController {
// ...
}
Where "Gallary" is you extension key in upper camel case.