Yii1, prettry url issue - url

I want to make url like this in Yii1 http://example.com/customer-name. It would list jobs for the customer-name, this customer-name will be changing dynamically for example customer-name can be
customer-name=IBM or customer-name=abc-mn or customer-name=xyz
The urls will be something like this
http://example.com/IBM
http://example.com/abc-mn
http://example.com/xyz
I have tried many tutorials but when I a try nothing works for me. Also I followed the http://www.yiiframework.com/doc/guide/1.1/en/topics.url

You new to configure the main.php config properly and have your controller action ready.
private/protected/config/main.php
'urlManager'=>array(
//path is slash separated format aka www.url.com/controller/action/getparam/getvalue
'urlFormat'=>'path',
'showScriptName'=>false,
'caseSensitive'=>true,
'rules'=>array(
//site is your controller, comapny is your action and the name is get variable actionCompany is waiting for.
'<name>' => 'site/company'
)),
private/protected/controllers/SiteController.php (alos make sure the actioname company is in accessRules if you user acceessControll filter).
public function actionCompany( $name )
{
/* your action code */
$this->render('test', array( 'test' => 'to_view' ) );
}
If this didn't help then you have to give us more of your code.

Related

TYPO3 - Retrieved TypoScript in itemsProcFunc are incomplete

I have following problem:
We are overriding the tt_content TCA with a custom column which has an itemsProcFunc in it's config. In the function we try to retrieve the TypoScript-Settings, so we can display the items dynamically. The problem is: In the function we don't receive all the TypoScript-Settings, which are included but only some.
'itemsProcFunc' => 'Vendor\Ext\Backend\Hooks\TcaHook->addFields',
class TcaHook
{
public function addFields($config){
$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
$configurationManager = $objectManager->get('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface');
$setup = $configurationManager->getConfiguration(
\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT
);
}
$setup is now incomplete and doesn't contain the full TypoScript, for example some of the static-included TypoScript is missing.
Used TYPO3 7 LTS (7.6.18), PHP 7.0.* in composer-mode.
Does anybody know where the problem is? Is there some alternative?
You maybe misunderstood the purpose of TypoScipt. It is a way of configuration for the Frontend. The Hook you mentioned is used in the TCA, whích is a Backend part of TYPO3. TypoScript usually isn't used for backend related stuff at all, because it is bound to a specific page template record. Instead in the backend, there is the TSConfig, that can be bound to a page, but also can be added globally. Another thing you are doing wrong is the use of the ObjectManager and the ConfigurationManager, which are classes of extbase, which isn't initialized in the backend. I would recommend to not use extbase in TCA, because the TCA is cached and loaded for every page request. Instead use TSConfig or give your configuration settings directly to the TCA. Do not initialize extbase and do not use extbase classes in these hooks.
Depending on what you want to configure via TypoScript, you may want to do something like this:
'config' => [
'type' => 'select',
'renderType' => 'singleSelect',
'items' => [
['EXT:my_ext/Resources/Private/Language/locallang_db.xlf:myfield.I.0', '']
],
'itemsProcFunc' => \VENDOR\MyExt\UserFunctions\FormEngine\TypeSelectProcFunc::class . '->fillSelect',
'customSetting' => 'somesetting'
]
and then access it in your class:
class TypeSelectProcFunc{
public function fillSelect(&$params){
if( $params['customSetting'] === 'somesetting' ){
$params['items'][] = ['New item',1];
}
}
}
I had a similar problem (also with itemsProcFunc and retrieving TypoScript). In my case, the current page ID of the selected backend page was not known to the ConfigurationManager. Because of this it used the page id of the root page (e.g. 1) and some TypoScript templates were not loaded.
However, before we look at the solution, Euli made some good points in his answer:
Do not use extbase configuration manager in TCA functions
Use TSconfig instead of TypoScript for backend configuration
You may like to ask another question what you are trying to do specifically and why you need TypoScript in BE context.
For completeness sake, I tested this workaround, but I wouldn't recommend it because of the mentioned reasons and because I am not sure if this is best practice. (I only used it because I was patching an extension which was already using TypoScript in the TCA and I wanted to find out why it wasn't working. I will probably rework this part entirely.)
I am posting this in the hope that it may be helpful for similar problems.
public function populateItemsProcFunc(array &$config): array
{
// workaround to set current page id for BackendConfigurationManager
$_GET['id'] = $this->getPageId((int)($config['flexParentDatabaseRow']['pid'] ?? 0));
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$configurationManager = $objectManager->get(BackendConfigurationManager::class);
$setting = $configurationManager->getTypoScriptSetup();
$templates = $setting['plugin.']['tx_rssdisplay.']['settings.']['templates.'] ?? [];
// ... some code removed
}
protected function getPageId(int $pid): int
{
if ($pid > 0) {
return $pid;
}
$row = BackendUtility::getRecord('tt_content', abs($pid), 'uid,pid');
return $row['pid'];
}
The function getPageId() was derived from ext:news which also uses this in an itemsProcFunc but it then retrieves configuration from TSconfig. You may want to also look at that for an example: ext:news GeorgRinger\News\Hooks\ItemsProcFunc::user_templateLayout
If you look at the code in the TYPO3 core, it will try to get the current page id from
(int)GeneralUtility::_GP('id');
https://github.com/TYPO3/TYPO3.CMS/blob/90fa470e37d013769648a17a266eb3072dea4f56/typo3/sysext/extbase/Classes/Configuration/BackendConfigurationManager.php#L132
This will usually be set, but in an itemsProcFunc it may not (which was the case for me in TYPO3 10.4.14).

Laravel 5: remove default /?=value in url

I am using Laravel 5. In my Controller I am getting value from View like this method:
$params = array('' => Input::get("selected_category_id"));
then it showing in my log like this:
/api/zones/?=3
I try to modify which remove the single quote and equal symbol, like this:
$params = array(Input::get("selected_category_id"));
then it showing in my log like this:
/api/zones/?0=3
Can I set my url to be like this format:
/api/zones/3
thanks for any help!
As far as I understand your questions, you need to create a new route for it:
Route::post('/api/zones/{id}','YourController#processInput');
In the above route, replace YourController with the controller you are using to process the input and replace processInput with the method that actually processes it.
So, your controller would now have access to the category:
public function processInput(Request $request, $id)
{
$categoryID = $id;
}

action helper and routing priority laravel 5

I have two rules
Route::get('this-is-an-awesome-route', 'Ads#getIndex');
Route::controller('ads', 'Ads');
action('Ads#getIndex') renders
http://my-awesome-domain/ads
I want
http://my-awesome-domain/this-is-an-awesome-route
What's the problem ?
For some reason from Laravel 4.2 to Laravel 5 the logic changed a little bit. The line you wrote was working before, you just have to reverse everything as the router isn't processing your code the same way.
Tested and working solution
Route::controller('ads', 'Ads');
Route::get('this-is-an-awesome-route', 'Ads#getIndex');
The first route will be overwritten by the second one.
The second route is rewriting the first route declaration. Let's see:
// Ads#getIndex will be called
Route::get('this-is-an-awesome-route', 'Ads#getIndex');
// Ads#getIndex will be called too by native definition
Route::controller('ads', 'Ads');
Because of Route::controller('ads', 'Ads') is called as latest declaration it will overwrite the previous one. So, you have at least two ways to achieve this task
You could create a new function into Ads controller just to response to the first route:
Route::get('this-is-an-awesome-route', 'Ads#awesome');
Then:
public function awesome(){
// do stuff here
}
Rename the route name for your controller
Route::controller('ads', 'Ads', [
'getIndex' => 'ads.getHome',
]);
Now your Route::controller('ads', 'Ads'); will respond to getHome() instead getIndex() as per renamed route:
public function getHome(){
// do stuff for getIndex() definitions here
}

getarguments in typo3 from URL

I am working in TYPO3 .....
how can i get arguments from URL
i passed arguments in url like this ,
as a template in resources folder , file name : list.html
<f:form action="update" object="{hotel}" arguments="{myArgument: argumentname}" name="hotel">
and in controller in updateAction() , i want to fetch that agruments , so i write like this ,
$this->view->assign('hotel', array('test' => 'hello' . isset($this->arguments['myArgument']) .'##' . $this->getParametersSafely('myArgument')));
and i make the function in controller...
public function getParametersSafely ($parameterName) {
if ($this-> request-> hasArgument ($parameterName)) {
return $this-> request->getArgument($parameterName);
}
}
So please help me this is not working
I guess "this is not working" means the string in the fluid variable {hotel} is kind of not what you expect? Or what exactly is not working?
First of all isset() returns a boolean, taht you should not just add to your string.
Secondly, if you use arguments="{myArgument: argumentname}"fluid expects argumentname to be a variable passed to the template. If you want to pass a string, you need to specify it: arguments="{myArgument: 'argumentname'}".

How can I change the preferred language when clicking in an anchor link (Kohana's i18n)?

I have a es.php and a tl.php in the i18n folder:
es.php:
<?php defined('SYSPATH') or die('No direct script access.');
return array(
'Good Morning' => 'Buenos Dias',
);
tl.php (is the abbreviation of a human language. No idea which one):
<?php defined('SYSPATH') or die('No direct script access.');
return array(
'Good Morning' => 'Magandang Umaga',
);
view file site.php:
<p><?php echo __('Good Morning'); // would produce 'Buenos dias'?></p>
I'm using Kohana 3. Right now, the only way known method to change the language is to modify I18n::lang('es-es'); in bootstrap.php.
How can I change the preferred language when clicking in an anchor link (an anchor link inside site.php)?
insert this in your before method inside your main controller:
I18n::$lang = 'es-es';
good example of how you can do this with cookies can be found inside the userguide module main controller

Resources