FuelPHP - Why is there a backslash in this code: $email = \Email::forge(); - fuelphp

Why is there a backslash in this code?
$email = \Email::forge();
I am reading over the Email package documentation on FuelPHPs site. The above code is their example. Why is there a backslash?

Because the class is declared in global namespace and seems to be used in some other namespace, where it's required.
Here's complete manual about namespaces:
http://www.php.net/manual/en/language.namespaces.php

Related

Create a link in backend to a frontend page

I would link to create a link to a frontend page inside a backend module.
Using:
<f:link.page pageUid="40" >Link</f:link.page>
Doesn't work. It generates a link to the current backend module.
Any solution ?
Since TYPO3 v9 you can use the following lines of code:
use TYPO3\CMS\Core\Site\SiteFinder;
use TYPO3\CMS\Core\Site\Entity\Site;
use TYPO3\CMS\Core\Routing\PageRouter;
$siteFinder = GeneralUtility::makeInstance(SiteFinder::class);
$site = $siteFinder->getSiteByPageId($pageId);
$router = $site->getRouter();
$frontendUrl = (string) $router->generateUri($pageId);
Thanks to Benni Mack # TYPO3Camp Mitteldeutschland
This is a very long story but the gist is: it is not possible to create FE links in BE/CLI context without a lot of workarounds and dummy objects/values.
If possible you should use solutions like pagepath which generate URLs for an eID script which performs the actual URL generation on demand.

Silverstripe hash link rewriting putting unwanted slash in link

Ok so I am developing a site in Silverstripe CMS that is using anchor links on one of it's pages. Thing is that in Silverstripe there is a rewrite going on that puts slashes before the hash in your links.
So in the docs it explains that you can put this in your YAML to disable slashes before hashes: http://doc.silverstripe.org/en/developer_guides/templates/how_tos/disable_anchor_links/
Which I have done like so (YAML validates ok):
_config/app.yml:
SSViewer: rewrite_hash_links: false
And then in my template file this is how I am constructing my link with anchor:
Link
(note that this template file is for a dataobject, I'm not sure if that has any baring)
And the outputted link is:
/cnc-machining/#made-to-order
but should be:
/cnc-machining#made-to-order
I'm all out of ideas. Any pointers?
In your DataObject's getLink() method you can simply remove the trailing slash using rtrim:
public function getLink() {
//remove trailing slash from parent link
$parentLink = rtrim($this->ParentPage()->Link(), '/');
return $parentLink . '#' . $this->URLSegment;
}
Now in your template just run in DataObject's scope:
Link
Though i didn't notice any disadvantage with having the trailing slash in the url.
HTH, wmk

How to set a custom useragent string in Mojo::UserAgent

We have a bunch of code built around Mojo::UserAgent and migrating to MojoX::UserAgent is not quite an option. I wonder if there is a way to get/set user agent string in Mojo::UserAgent?
The current (Mojo 4.5) way is:
# Change name of user agent
$ua->transactor->name('MyUA 1.0');
See CPAN documentation here.
Use the name accessor:
my $name = $ua->name;
$ua->name('Mozilla/5.0');
(Note that in the 4.x release, the name accessor has been removed)

SilverStripe blog module translation

I noticed that the blog module for SS have hardcoded pieces of text - that I need to translate (in french). I found that the code is in /blog/templates/Includes/BlogSummary.ss but when I modify it, nothing changes on front-end...
I tried to run a /dev/build/?flush=all but nothing... still.
Any idea? Help would be much appreciated. Thanks in advance.
Have you set your locale? I recently set up a site in English & Spanish and used this setup.
// add similar code to your _config.php file
#Translatable::set_default_locale('en_US');
#Translatable::set_allowed_locales(array(
# 'en_US',
# 'es_US'
#));
Further, I had to add i18n::set_locale() code to the init() function in my content controller to get the template translations to work.
<?php
class SmartLanguageExtension extends DataObjectDecorator {
function contentcontrollerInit() {
i18n::set_locale(Translatable::get_current_locale());
}
}
In my case, I added an extension to the Page_Controller class for reusability later on.
// _config.php file
Object::add_extension('Page', 'SmartLanguageExtension');

Testing view helpers

I'm currently working on a Rails plugin used for generating iPhone specific HTML meta-tags. I'm trying to use ActionView::TestCase for unit tests but keep getting the same error. See file contents and error below. Any ideas or help would be much appreciated.
test_helper.rb
require 'rubygems'
require 'test/unit'
require 'active_support'
require 'action_view'
require File.join(File.dirname(__FILE__), '..', 'lib', 'iphone_helper')
iphone_test_helper.rb
require 'test_helper'
class IphoneHelperTest < ActionView::TestCase
test 'br' do
tag = tag('br')
assert_tag_in tag, '<br />'
end
end
error
RuntimeError: In order to use #url_for, you must include routing helpers explicitly. For instance, `include Rails.application.routes.url_helpers
Awful and hacky workaround that worked for me (since I am working on a gem and not in a full rails environment):
require 'ostruct'
module ActionController::UrlFor
def _routes
helpers = OpenStruct.new
helpers.url_helpers = Module.new
helpers
end
end
Did you try to include the respective Module in an old-fashioned way?:
include ActionDispatch::Routing::RouteSet
If a NameError is raised telling you that ActionDispatch is unknown you might have to require 'action_dispatch'.
Maybe a stupid question, but is the fact that the class name and the file name don't match possibly a problem (IphoneHelperTest vs. iphone_test_helper.rb)? Sometimes that leads to classes not being loaded.