I had problem with the error from Zend Framework 1.9 when was building routers for friendly url`s. Te error was:
cannot assemble. reversed route is not specified
Was not so easy to find the solution, so i want to share if anyone will struggle with this like me.
Like they wrote in zend manual:
"Since regex patterns are not easily reversed, you will need to prepare a reverse URL if you wish to use a URL helper or even an assemble method of this class. This reversed path is represented by a string parsable by sprintf() and is defined as a fourth construct parameter:"
$route = new Zend_Controller_Router_Route_Regex(
'archive/(\d+)',
array( ... ),
array('year' => 1),
'archive/%s'
);
So basically all You have to do is to add
'archive/%s'
line to Your router params.
I found the solution in this thread
Zend community thread
Related
I want to use the Respect/Validation library in PHP. I know how to use it but currently I'm using it in a project in German language and of course, I also want the error messages in German.
For language translation, there is a section in the documentation but I don't really get it and I did not found any answer yet.
They're talking about a translator that should handle the translation of the messages. As a second parameter they're giving "gettext" but I don't know what this should be and how this should handle the translation.
Can anybody explain me how this works?
Respect/Validation won't do the translation for you, you should use a different project, library or function to do that. It won't leave you empty handed though, as the documentation states.
First, you should try to understand how translation libraries work (such as gettext()) and then read PHP documentation on Callables. Then it is a matter of choosing a library, creating the translations and calling setParam('translator', 'callable') method on the exception instance.
A quick introduction to your problem:
Translations are done based on a source: it can be a file, a database or something else, depending on which library you use.
Respect/Validation exception messages use the same pattern: {{name}} is invalid.. Where {{name}} will be replaced by the input given or the name if setName() was called on that rule.
You can see all messages you need to translate under the Respect\Validation\Exceptions namespace.
Usually, every library provide a single function/method to translate a given string. This is the method/function you want to set on the $exception->setParam() call.
If you ever translate all exception messages, we would love to make them available to everyone else.
PS: You could also make this question on the repository page, more people would help and we could also improve the way translations are handled by the library in the future.
I just changed all Exception defaultTemplates property, it works for me.
class Localization
{
public function init()
{
$this->validation();
}
public function validation()
{
$prefix = '\\Respect\\Validation\\Exceptions\\';
$localize = [
'EmailException' => 'local message',
'NotEmptyException' => 'local message'
];
foreach($localize as $class => $message) {
($prefix.$class)::$defaultTemplates[
ValidationException::MODE_DEFAULT][ValidationException::STANDARD] = $message;
}
}
}
$localization = new Localization();
$localization->init();
latetly on a legacy project I have to use Zend framework 1.2 :-(.
I find Zend to have too many levels of indirection and magic functions and I am not 100% sure about wheather it urldecodes the request params. It's also not stated in the docs.
So example if you have a request object and you do:
$ntrack = $request->getParam('ntrack');
Will $ntrack contain the urldecoded of ntrack or not?
So far by my tests it seems so, but I couldn't trace or be confident about this...
I checked the following classes and found no evidence of urldecoding wierd...
Classes I checked:
Zend_Controller_Request_Abstract
Zend_Controller_Request_Http which implements the above
ZF doesn't need to do this since PHP does this automatically. You can assume $request->getParam('ntrack') will give you the URL decoded version.
I would appreciate if anyone could guide me on the correct way on doing an ItemLookup by ISBN using the Zend Amazon Service module (with Zend 2.0).
Here is my attempt:
$query = new ZendService\Amazon\Query($appId, 'UK', $secretKey);
$query->Category('Books')->IdType('ISBN')->ItemID('978-0321784070')->AssociateTag($tag);
$result = $query->ItemLookup();
But I get the following errors:
Missing argument 1 for ZendService\Amazon\Amazon::itemLookup(), called in D:\wamp\www\site\controllers\dev.php on line 122 and defined
Undefined variable: asin
There is no way I can define the ASIN because the only information I will have is the ISBN.
I have already consulted the Zend Service Amazon user guide in the zend framework website but it is outdated and doesn't demonstrate how to do an ISBN lookup. I have also looked at the demo that came with the zend amazon package but that only details how to do item searches, not lookups.
Here is a way to get the ISBN search working, it took me a little while to get it figured out as well. The problem was that in order to search for ISBN you must use the ItemLookup method rather than the ItemSearch method which was getting set by the query() method.
There may be a better way to get this to work using the OO interface but I haven't tried that yet.
$query = new ZendService\Amazon\Query($appId, 'US', $secretKey);
$item = $query->itemLookup('9780321784070',
array('SearchIndex' => 'Books',
'AssociateTag' => $tag,
'IdType' => 'ISBN',
'ResponseGroup' => 'Small',));
Searching by ISBN should return a single ZendService\Amazon\Item object rather than an array of results. Also be aware, if you search by ISBN-13, you need to strip the - from the number or it won't find a match.
Credit to this blog post by Manas Tungare which hinted to me that we need to use IteamLookup instead of ItemSearch.
how we could create translate validate error messages on zend framework?
someone could give a example ?
thanks
From the ZF Manual on Zend_Validate Validation Messages
$validator = new Zend_Validate_GreaterThan();
$validator->setMessage('Please enter a lower value',
Zend_Validate_GreaterThan::NOT_GREATER);
And also:
Zend Framework is shipped with more than 45 different validators with more than 200 failure messages. It can be a tendious task to translate all of these messages. But for your convinience Zend Framework comes with already pre-translated validation messages. You can find them within the path /resources/languages in your Zend Framework installation.
[...]
So to translate all validation messages to german for example, all you have to do is to attach a translator to Zend_Validate using these resource files.
$translator = new Zend_Translate(
'array',
'/resources/languages',
$language,
array('scan' => Zend_Locale::LOCALE_DIRECTORY)
);
Zend_Validate_Abstract::setDefaultTranslator($translator);
Of course, you can also provide your own translations. All you have to do is load make them available to the translation adapter. Basically you just swap out the part shown above to your custom path.
I just want to improve a little bit the answer from Gordon:
a working example is
$translator = new Zend_Translate(
'array',
'resources/languages', // you need to copy the resources folder
// (from your Zend Framework installation)
// in the application folder
'it', // 'it' for italian, 'fr' for french, etc.
// Just look at the directories
// Zend_Translate, NOT Zend_Locale
array(
'scan' => Zend_Translate::LOCALE_DIRECTORY
)
);
Zend_Validate_Abstract::setDefaultTranslator($translator);
Cheers!
Bruno
I'm trying to implement a simple way to manage static pages in CakePhp, as described in this article.
The problem I'm facing is that App::import() doesn't seem to import the required class in the routes.php file.
The code is the following:
App::import('Model','StaticPage');
$page = new StaticPage();
$slugs = $page->find('list', array(
'fields' => array('StaticPage.slug'),
'order' => 'StaticPage.slug DESC'
));
I'm getting the error: Fatal error: Class 'StaticPage' not found in ...
This class is present in the models folder (models/StaticPage.php).
I just started CakePhp a few weeks ago and I guess I'm missing a simple thing here...
I'm using CakePhp 1.3 and Php 5.2.42.
I think the reason it doesn't work is because you don't follow CakePHP's naming conventions for file names: file names are lowercase and underscored. So renaming your file to static_page.php should fix the problem.
Having taken a quick look at the article you reference, your snippet doesn't match up. You're importing the ClassRegistry class (which doesn't need to be imported) and then trying to instantiate a StaticPage. I'd recommend removing the AppImport reference all together and using ClassRegistry:
$page = ClassRegistry::init( 'StaticPage' );
You don't need the AppImport line because ClassRegistry::init() both loads the model and instantiates the object.
The other (potential) problem I see is that your model file name doesn't follow convention. It should be models/static_page.php. Cake's inflection may not be handling the deviation from the norm.
Like the error says: You are missing the Class StaticPage. Are you sure that you have this file? If you do, sure that it's in right place, has the right filename so the autoloader can find it?.