I'm trying to run application with Silex FW. I have similar source code as in example:
require_once __DIR__.'/silex.phar';
$app = new Silex\Application();
$app['debug'] = true;
$app->register(new Silex\Provider\TwigServiceProvider(), array(
'twig.path' => __DIR__ . '/views',
'twig.class_path' => __DIR__ . '/vendor/twig/lib',
));
$app->get('/hello/{name}', function ($name) use ($app) {
return $app['twig']->render('hello.twig', array(
'name' => $name,
));
});
$app->run();
But I'm getting this error:
Fatal error: Class 'Twig_Environment' not found in phar:///var/www/silex/silex.phar/src/Silex/Provider/TwigServiceProvider.php on line 40
Stack trace:
1. {main}() /var/www/silex/index.php:0
2. Silex\\Application->run() /var/www/silex/index.php:20
3. Silex\\Application->handle() phar:///var/www/silex/silex.phar/src/Silex/Application.php:396
4. Symfony\\Component\\HttpKernel\\HttpKernel->handle() phar:///var/www/silex/silex.phar/src/Silex/Application.php:411
5. Symfony\\Component\\HttpKernel\\HttpKernel->handleRaw() phar:///var/www/silex/silex.phar/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/HttpKernel.php:72
6. call_user_func_array() phar:///var/www/silex/silex.phar/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/HttpKernel.php:128
7. {closure}() phar:///var/www/silex/silex.phar/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/HttpKernel.php:128
8. Pimple->offsetGet() phar:///var/www/silex/silex.phar/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/HttpKernel.php:15
9. {closure}() phar:///var/www/silex/silex.phar/vendor/pimple/pimple/lib/Pimple.php:81
10. Silex\\Provider\\{closure}() phar:///var/www/silex/silex.phar/vendor/pimple/pimple/lib/Pimple.php:120
This problem was also posted on GitHub.
Solution is to use Composer and autoload.php.
With that approach, your twig.class_path probably needs to be vendor/twig/twig/lib (extra twig directory) ...
But twig.class_path is actually unnecessary, with composer, which is the better approach (as kuboslav notes).
Related
Hi I need interate twig to Slim application, I install twig with composer and im my script I have
<?php
use Slim\Slim;
use Slim\Views\Twig;
use Noodlehaus\Config;
use Codecourse\User\User;
session_cache_limiter(false);
session_start();
ini_set('display_errors','On');
define('INC_ROOT', dirname(__DIR__));
require INC_ROOT.'/vendor/autoload.php';
$app = new Slim([
'mode' => file_get_contents(INC_ROOT.'/mode.php'),
'view' => new Twig(),
'template.path' => INC_ROOT . '/app/views'
]);
$app->view->setTemplatesDirectory("/views");
$app->configureMode($app->config('mode'), function() use ($app) {
$app->config = Config::load(INC_ROOT . "/app/config/{$app->mode}.php");
});
echo $app->config->get('db.driver');
require 'database.php';
$app->container->set('user', function() {
return new User;
});
$app->get('/', function() use ($app) {
$app->render('home.php');
});
when I run script I obtain this error:
Type: Twig_Error_Loader
Message: The "/views" directory does not exist.
File:
C:\xampp\htdocs\authentication\vendor\twig\twig\lib\Twig\Loader\Filesystem.php
The Slim documentation for configuring the template path might be a little misleading; you only need to set template.path or call View::setTemplatesDirectory but not both.
If you wanted to use the latter, then it would simply be :
$app->view->setTemplatesDirectory(INC_ROOT . '/app/views');
My stupid mistake
i must use
'templates.path' => INC_ROOT . '/app/views'
and I have
'template.path' => INC_ROOT . '/app/views'
i am trying to install 'EdpModuleLayouts'
i have followed the instruction for the module here:
i also followed the issue here:
i. e; I placed the following code in my application.config.php?
return array(
'modules' => array(
... ,
'EdpModuleLayouts'
)
);
i then placed the following code in my module config
'view_manager' => array(
'template_path_stack' => array(
'workers' => __DIR__ . '/../view',
'Workers/layout' => __DIR__ . '/../view/layout/layout.phtml'
),
),
'module_layouts' => array(
'Workers' => 'Workers/layout'
),
i got the following error report:
Fatal error: Uncaught exception 'Zend\View\Exception\RuntimeException'
with message 'Zend\View\Renderer\PhpRenderer::render: Unable to render
template "Workers/layout"; resolver could not resolve to a file' in
zendframework\zendframework\library\Zend\View\Renderer\PhpRenderer.php
on line 499
The error message is so specific.
Unable to render template "Workers/layout"
This means that there is no template Workers/layout defined within the view_manager configuration. And the trick here is that you made a simple mistake of placing the configuration at the wrong place.
template_path_stack is used to give the view_manager information about some folders where template files are mapped going by their file-path.
template_map is used to give the view_manager information about which file covers a specific template.
The difference of the two can easily be seen when checking the module.config.php of the ZendSkeletonApplication. With this in mind, all you have to do is to change your configuration.
Another hint: don't CamelCase configuration keys, keep them lowercased ;)
'view_manager' => array(
'template_path_stack' => array(
'workers' => __DIR__ . '/../view',
),
'template_map' => array(
// consider to make this lowercase "workers/layout"
'Workers/layout' => __DIR__ . '/../view/layout/layout.phtml'
)
),
'module_layouts' => array(
'Workers' => 'Workers/layout'
),
Is there any alternative for getting uri with changed parameter as $this->request->uri($params) in KO 3.2?
Example:
//Kohana 3.1 ; current uri = articles/show/10 (<controller>/<action>/<id>)
$this->request->uri(array('id' => 11)); // return 'articles/show/11'
Thanks
Since 3.2 there is no "short" way for this, because now $this->request->uri() returns current URI. Use $this->request->route()->uri() with all params you need:
$params = array('id' => 11); // what params you want to change
$params += $this->request->param(); // current request params
$params += array(
// note that $this->request->param() doesnt contain directory/controller/action values!
'directory' => $this->request->directory(),
'controller' => $this->request->controller(),
'action' => $this->request->action(),
);
$uri = $this->request->route()->uri($params);
Of course, you can create a special method for this (something like $this->request->old_uri(array('id' => 11))).
Here is an issue link for that API change.
I am handling file upload field in a form using Drupal 6 form APIs. The file field is marked as required.
I am doing all the right steps in order to save and rename files in proper locations.
upload form
$form = array();
....
$form['image'] = array(
'#type' => 'file',
'#title' => t('Upload photo'),
'#size' => 30,
'#required' => TRUE,
);
$form['#attributes'] = array('enctype' => "multipart/form-data");
...
form validate handler
$image_field = 'image';
if (isset($_FILES['files']) && is_uploaded_file($_FILES['files']['tmp_name'][$image_field])) {
$file = file_save_upload($image_field);
if (!$file) {
form_set_error($image_field, t('Error uploading file'));
return;
}
$files_dir = file_directory_path();
$contest_dir = 'contest';
if(!file_exists($files_dir . '/' . $contest_dir) || !is_dir($files_dir . '/' . $contest_dir))
mkdir($files_dir . '/' . $contest_dir);
//HOW TO PASS $file OBJECT TO SUBMIT HANDLER
$form_state['values'][$image_field] = $file;
file_move($form_state['values'][$image_field], $files_dir."/" . $contest_dir . "/contest-". $values['email']. "-" . $file->filename);
}
else {
form_set_error($image_field, 'Error uploading file.');
return;
}
On submiting form
Form always reports an error Upload photo field is required. although files are getting uploaded. How to deal with this issue?
How to pass file information to submit handler?
your handler is wrong. You never should touch $_FILES or $_POST variables in drupal, instead you should only use the drupal tools. Said that, the implementation you should is like that:
function my_form_handler(&$form,&$form_state){/** VALIDATION FILE * */
$extensions = 'jpeg jpg gif tiff';
$size_limit = file_upload_max_size();
$validators = array(
'my_file_validate_extensions' => array($extensions),
'my_file_validate_size' => array($size_limit),
);
$dest = file_directory_path();
if ($file = file_save_upload('image', $validators, $dest)) {
//at this point your file is uploaded, moved in the files folder and saved in the DB table files
}
}
I think you'll want to use the filefield module and append it to a form, as described in:
Drupal Imagfield/Filefield in custom form
The question has a link to the solution:
http://sysadminsjourney.com/content/2010/01/26/display-cck-filefield-or-imagefield-upload-widget-your-own-custom-form
From the Drupal 6 Form API docs:
"Note: the #required property is not supported (setting it to true will always cause a validation error). Instead, you may want to use your own validation function to do checks on the $_FILES array with #required set to false. You will also have to add your own required asterisk if you would like one."
Old post, but I'm looking for something similar and figured I add that.
I'm using Drupal 6 to run a gallery I've created. I need to take a parameter from the AJAX request lets say "food" and pass that argument to a view I've created (Views 2) where "food" is a taxonomy term that I am using to get the data I want in return. Everything is working just fine and in my module's method for loading the view I can load the entire view because in the settings you have 'if no argument get all values', but I can't seem to pass arguments to it. Here is the method...
function ajax_methods_menu()
{
$items = array();
$items['admin/settings/ajax_methods'] = array(
'title' => t('AJAX Methods settings.'),
'description' => t('Define settings for the AJAX Methods'),
'page callback' => 'drupal_get_form',
'page arguments' => array('ajax_methods_admin'),
'access arguments' => array('access administration pages'),
'type' => MENU_NORMAL_ITEM
);
$items['gateway'] = array(
'title' => 'AJAX Gateway',
'page callback' => 'ajax_methods_get_items',
'type' => MENU_CALLBACK,
'access arguments' => array('access content')
);
return $items;
}
function ajax_methods_get_items($args)
{
$content = views_get_view('All_Images');
return drupal_json(array('status' => 0, 'data' => $content->preview('default')));
exit;
}
In looking at the documentation views_get_view() doesn't seem to allow for arguments although I believe they are being passed to my ajax_methods_get_items() method. Thanks for reading!
Got it figured out, I needed to add
return arg(1);
seems to be working pretty well.