Skip controller and action in url generation - url

TYPO3 version is 7.6.0.
Generate link:
<f:link.action action="single" class="title" pageUid="{settings.pidDetails}" additionalParams="{unid: '{unid}'}" noCacheHash="true">Link text</f:link.action>
Result:
http://example.com/property/flats/?unid=12345&tx_ext_extp1%5Baction%5D=single&tx_ext_extyp1%5Bcontroller%5D=Ext
Need:
Skip controller and action in url generation - http://example.com/property/flats/?unid=12345

You can use realurl extension for clean url.
After installation, edit realurl_autoconf.php file which located in typo3conf folder.
function user_encodeSpURL_postProc(&$params, &$ref) {
$params['URL'] = str_replace('blog/post/article/', 'blog/post/', $params['URL']);
}
function user_decodeSpURL_preProc(&$params, &$ref) {
$params['URL'] = str_replace('blog/post/', 'blog/post/article/', $params['URL']);
}
$GLOBALS['TYPO3_CONF_VARS']['FE']['addRootLineFields'].= ',tx_realurl_pathsegment';
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl'] = array (
'_DEFAULT' => array (
'init' => array (
'enableCHashCache' => '1',
'appendMissingSlash' => 'ifNotFile',
'enableUrlDecodeCache' => '1',
'enableUrlEncodeCache' => '1'
),
'redirects' => array (
),
'preVars' => array (
'0' => array (
'GETvar' => 'no_cache',
'valueMap' => array (
'nc' => '0'
),
'noMatch' => 'bypass',
),
'1' => array (
'GETvar' => 'L',
'valueMap' => array (
'de' => '0',
'en' => '1'
),
'noMatch' => 'bypass'
),
'2' => array (
'GETvar' => 'cHash',
'noMatch' => 'bypass',
),
),
'pagePath' => array (
'type' => 'user',
'userFunc' => 'EXT:realurl/class.tx_realurl_advanced.php:&tx_realurl_advanced->main',
'spaceCharacter' => '-',
'languageGetVar' => 'L',
'rootpage_id' => '1' // your root UID
),
'fixedPostVars' => array(
),
'postVarSets' => array(
'_DEFAULT' => array(
'controller' => array(
array(
'GETvar' => 'tx_news_pi1[action]',
'noMatch' => 'bypass'
),
array(
'GETvar' => 'tx_news_pi1[controller]',
'noMatch' => 'bypass'
)
),
'authentication' => array(
array(
'GETvar' => 'tx_eventmanagementtool_ext1[action]',
),
),
'dateFilter' => array(
array(
'GETvar' => 'tx_news_pi1[overwriteDemand][year]',
),
array(
'GETvar' => 'tx_news_pi1[overwriteDemand][month]',
),
),
'page' => array(
array(
'GETvar' => 'tx_news_pi1[#widget_0][currentPage]',
),
),
),
),
'fileName' => array (
//'defaultToHTMLsuffixOnPrev' => '.html',
'acceptHTMLsuffix' => 1,
'index' => array (
'rss.xml' => array (
'keyValues' => array (
'type' => '100'
),
),
'rss091.xml' => array (
'keyValues' => array (
'type' => '101'
),
),
'rdf.xml' => array (
'keyValues' => array (
'type' => '102'
),
),
'atom.xml' => array (
'keyValues' => array (
'type' => '103'
),
),
'sitemap.xml' => array (
'keyValues' => array (
'type' => '776'
),
),
),
),
)
);
You can use bypass method to remove controller and action from url like:
'controller' => array(
array(
'GETvar' => 'tx_news_pi1[action]',
'noMatch' => 'bypass'
),
array(
'GETvar' => 'tx_news_pi1[controller]',
'noMatch' => 'bypass'
)
)

Go to your Extension folder.
In Configuration –>TypoScript –> setup.txt write below code:
plugin.tx_[your_extensionname].features.skipDefaultArguments = 1
Warning: This only works if you don’t use switchableControllerActions in your flexform.

Related

select a SF2 choice option

My code for my form ( i am using Silex):
$test = array(
'Swedish Cars' => array(
'volvo' => 'Volvo',
'saab' => 'Saab',
),
'German Cars' => array(
'mercedes' => 'Mercedes',
'audi' => 'Audi'
)
);
$form = $app['form.factory']->createBuilder('form')
->add('title','text',array(
'attr' => array(
'placeholder' => 'Title of your Album'
)))
->add('description','textarea',array(
'attr' => array(
'placeholder' => 'Describe your Album'
)))
->add('groups', 'choice', array(
'choices' => $test,
'multiple' => true,
'attr' => array(
'data-placeholder' => 'Add your Groups ...'
),
))
The choices are defined as an multi-array, so I get <option> with <optgropup>. How can I enable in SF2, that some options are selected?
Use the data option:
->add('groups', 'choice', array(
'choices' => $test,
'multiple' => true,
'attr' => array(
'data-placeholder' => 'Add your Groups ...',
'data' => $selected_value
),
where $selected_value can be a single value like 'value_1' or an simple array with multiple values array('value_1', 'value_2') to select.

Zend Framework 2 MyTaskList tutorial issue

I'm trying to learn zend framework, i started to do this tutorial: getting-started-with-zend-studio
When i finished the tutorial i found out that the route what we have set up in this tutorial namely: http://localhost/MyTaskList/task which should fetch all tasks, actually return with a 404 error (not found).
Any help would be really appreciate.
Here are my files: link
This is the mysql DB script:
CREATE TABLE task_item (
id INT NOT NULL AUTO_INCREMENT,
title VARCHAR(100) NOT NULL,
completed TINYINT NOT NULL DEFAULT ’0’,
created DATETIME NOT NULL,
PRIMARY KEY (id)
);
INSERT INTO task_item (title, completed, created)
VALUES (’Purchase conference ticket’, 0, NOW());
INSERT INTO task_item (title, completed, created)
VALUES (’Book airline ticket’, 0, NOW());
INSERT INTO task_item (title, completed, created)
VALUES (’Book hotel’, 0, NOW());
INSERT INTO task_item (title, completed, created)
VALUES (’Enjoy conference’, 0, NOW());
UPDATE
This is my module.config.php:
return array(
'controllers' => array(
'invokables' => array(
'Checklist\Controller\Task' => 'Checklist\Controller\TaskController',
),
),
'router' => array(
'routes' => array(
'task' => array(
'type' => 'Segment',
'options' => array(
'route' => '/task[/:action[/:id]]',
'defaults' => array(
'__NAMESPACE__' => 'Checklist\Controller',
'controller' => 'Task',
'action' => 'index',
),
'constraints' => array(
'action' => '^add|edit|delete$',
'id' => '[0-9]+',
),
),
),
),
),
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:controller[/:action]]'
, )
, )
, ),
'view_manager' => array(
'template_path_stack' => array(
'Checklist' => __DIR__ . '/../view',
),
),
);
url -localhost/MyTaskList/task
i run the project on my development server and after i removed task and added checklist on the comment below and i got a db connection error so i assume it works now.
update:
Yea well i had to rewrite some things!
update 2:
Back to the original.
url -localhost/MyTaskList/task
<?php
return array(
'controllers' => array(
'invokables' => array(
'Checklist\Controller\Task' => 'Checklist\Controller\TaskController',
),
),
'router' => array(
'routes' => array(
'task' => array(
'type' => 'Literal',
'options' => array(
'route' => '/task',
'defaults' => array(
'__NAMESPACE__' => 'Checklist\Controller',
'controller' => 'Task',
'action' => 'index',
),
'constraints' => array(
'action' => '^add|edit|delete$',
'id' => '[0-9]+',
),
),
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:controller[/:action]]',
),
),
),
),
),
),
'view_manager' => array(
'template_path_stack' => array(
'checklist' => __DIR__ . '/../view',
),
),
);

Validations in zend framework 2

I have defined fieldsets for form in zend framework 2.
$this->add ( array (
'name' => 'unitnumber',
'options' => array (
'label' => 'Unit Number:'
)
) );
$this->add ( array (
'name' => 'streetdirprefix',
'options' => array (
'label' => 'Street Direction Prefix:'
)
) );
$this->add ( array (
'name' => 'streetnumber',
'options' => array (
'label' => 'Street Number:'
)
) );
I want to set required field for unitnumber only. Not for other fields.
I have writen a function..
public function getInputFilterSpecification()
{
return array (
'name' => array(
'required' => true,
)
);
}
But, It's asking to fill all the fields. Can anyone help me out in this. Thanks.
$inputFilter->add(array(
'name' => 'artist',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 1,
'max' => 100,
),
),
),
));
References:
http://framework.zend.com/manual/2.2/en/user-guide/forms-and-actions.html
http://framework.zend.com/manual/2.2/en/modules/zend.input-filter.intro.html
In Zend 2, the "InputFilter" works more like in "strict" mode.
i.e. It requires you to specify if the elements mentioned in the InputFilter should have the 'required' value as TRUE or FALSE.
$this->add ( array (
'name' => 'unitnumber',
'required' => true, //Code Added
'options' => array (
'label' => 'Unit Number:'
)
));
$this->add ( array (
'name' => 'streetdirprefix',
'required' => false, //Code Added
'options' => array (
'label' => 'Street Direction Prefix:'
)
));
$this->add ( array (
'name' => 'streetnumber',
'required' => false, //Code Added
'options' => array (
'label' => 'Street Number:'
)
));

ZF2 - Trying to create a route like ZF1

I actually have 2 modules (Application and Admin) in my ZF2 application and I want a url routing like in ZF1. I currently have the following route:
'router' => array
(
'routes' => array
(
'admin' => array
(
'type' => 'Segment',
'options' => array
(
'route' => 'admin/[:controller[/:action]]',
'constraints' => array
(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array
(
'__NAMESPACE__' => 'Admin\Controller',
'controller' => 'Index',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array
(
'wildcard' => array
(
'type' => 'Wildcard'
)
)
),
),
),
So it will match "/admin", "/admin/controller", "/admin/controller/action" but not "/controller/action".
Now I need a route to the Application module. The problem is that if I simply use a route like that for the module Application, this new route would match "/admin/controller" as controller = "admin" and action = "controller".
I also tried the following regex route in the application:
'application' => array
(
'type' => 'Regex',
'options' => array
(
'regex' => '/(?<controller>^(?!(admin)$)[a-zA-Z][a-zA-Z0-9_-]*)?' .
'(/[a-zA-Z][a-zA-Z0-9_-]*)?',
'spec' => '/%controller%/%action%',
/*'constraints' => array
(
//The controller cannot be "admin"
'controller' => '^(?!(admin)$)[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),*/
'defaults' => array
(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Index',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array
(
'wildcard' => array
(
'type' => 'Wildcard'
)
)
),
But it's not getting the variables "controller" and "action".
Does anyone have a suggestion of how to solve that?
mind the route order: routes are handled using a LIFO stack, so what comes last in the array comes first when matching request urls.
this means that you always have to define the most generic routes first to prevent them from matching similar but more specific ones.
using the following order shouldn't need any constraint on the controller parameter, because anything starting with /admin will be matched first
'route1' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:controller[/:action]]',
'defaults' => array (
'controller' => 'controller',
'action' => 'index',
),
),
),
'route2' => array(
'type' => 'Segment',
'options' => array(
'route' => '/admin[/:controller[/:action]]',
'defaults' => array (
'controller' => 'admin-controller',
'action' => 'index',
),
),
),
furthermore, you can always specify excplicitly routes priority using the priority property (which should not be defined under the options array, but in the topmost array of the route), so the following code is equivalent to the previous example:
'route2' => array(
'type' => 'Segment',
'options' => array(
'route' => '/admin[/:controller[/:action]]',
'defaults' => array (
'controller' => 'admin-controller',
'action' => 'index',
),
),
),
'route1' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:controller[/:action]]',
'defaults' => array (
'controller' => 'controller',
'action' => 'index',
),
),
'priority' => -1,
),

Set the dynamic values in drop down in ZF2

I am using Zend Framework 2 and I would like to understand how I can add values to a drop down that is coming from a database.
The code is here:
$this->add(
array(
'name' => 'role',
'type' => 'Zend\Form\Element\Select',
'option' => array(
'label' => 'Role',
'value_option' => $roleData
)
)
);
Here the $roleData as an array and the value of array is as follows:
Array ( [0] => Array ( [id] => 1 [cell] => admin ) [1] => Array ( [id] => 2 [cell] => member ) [2] => Array ( [id] => 3 [cell] => guest ) [3] => Array ( [id] => 4 [cell] => Admina1 ) [4] => Array ( [id] => 5 [cell] => Admina1 ) )
Try 'value_options' instead of 'value_option'.
And your array has to be the following structure:
$options = array(
'1' => 'admin',
'2' => 'member',
'3' => 'guest',
'4' => 'Admina1',
'5' => 'Admina1'
);
$this->add(array(
'name' => 'yesorno',
'type' => 'Zend\Form\Element\Select',
'options' => array(
'label' => 'Yes or No Label',
'value_options' => array(
0 => 'No',
1 => 'Yes'
)
),
));

Resources