I need to display a flash message but the message gets gobbled up by another extension, so can I do something like this:
in my controller:
$message = t3lib_div::makeInstance('t3lib_FlashMessage', 'Valid.', 'Message Header', t3lib_FlashMessage::OK, FALSE );
$message->render();
echo "<br/>".__FUNCTION__.__LINE__."<br/>";
$this->redirect('validate_success');
and have the message show up somewhere on my page, but where, what tag? Or should I handle the passing of messages differently altogether?
I use typo3 v 4.5.3 extbase 1.3
Thanks
If you redirect with $this->redirect() the echo in the same action will never appear.
Correct usage of FlashMessage in TYPO3 4.5
In your controller/action:
$this->flashMessageContainer->add("Your message body", "Your message header", t3lib_FlashMessage::OK);
This will add the FlashMessage to a container which holds all FlashMessages in a global scope.
In your fluid template of the action you redirected to:
<f:flashMessages renderMode="div" />
Alternatively you can use renderMode="ul".
This is how I do it now:
$this->redirect('validate_failed', 'Coupon', 'coupons', array('coupon' => $result, 'filename' => $filename, 'message' => 'Expired.'));
avoiding the whole flashmessage thing and passing a other stuff I want as well.
and this is my couponcontroller method that catches that redirect:
/**
* action validate
* #param Tx_Coupons_Domain_Model_Coupon $coupon
* #param string $filename
* #param string $message
* #return void
*/
public function validate_failedAction(Tx_Coupons_Domain_Model_Coupon $coupon = NULL, $filename = '', $message = '') {
$this->view->assign('coupon', $coupon);
$this->view->assign('filename', $filename);
$this->view->assign('message', $message);
}
Related
when i submit a form and run form validation then it gaves me this error but my form validation is working on other page
In that file \vendor\laravel\framework\src\Illuminate\Validation\Validator.php
/**
* Handle dynamic calls to class methods.
*
* #param string $method
* #param array $parameters
* #return mixed
*
* #throws \BadMethodCallException
*/
public function __call($method, $parameters)
{
$rule = Str::snake(substr($method, 8));
if (isset($this->extensions[$rule])) {
return $this->callExtension($rule, $parameters);
}
throw new BadMethodCallException(sprintf(
'Method %s::%s does not exist.', static::class, $method
));
}
Errror= Method Illuminate\Validation\Validator::validateRequest does not exist
Maybe you wrote request instead of required? Like here:
$data = $request->validate([
'field' => 'request|string|max:255',
]);
Trying to fire validateRequest method suggest you were trying to use 'request' validation rule which doesn't exist.
All valid rules you can find here, but I think you just made a typo.
You should use a Validator facade class
In you Controller
use Validator;
See link Laravel validation
You can validate the form as below:
public function formSubmit(Request $request){
$request->validate([
'name' => 'required',
'address' => 'required',
'phone' => 'required',
]);
$customer =Customer::insert([
'name' => $request->name,
'address' => $request->address,
'phone' => $request->phone
]);
dd($customer);
echo "Data send Successfully";
}
you may try this method
$request->validate([
'sex' => ['required',Rule::in('f','m')]
]);
this one is worked for me
$request-> validate([
'name'=>'required',
'email'=>'required|email'|'unique:admins',
'password '=>'required|min:5|max:12'
After how many minutes of debugging the error was there's an extra '' in required and a space after 'password '. Please see corrected code below
$request-> validate([
'name'=>'required',
'email'=>'required|email|unique:admins',
'password'=>'required|min:5|max:12'
In my case, I forget to import Validator file and just added this line at the top of controller file where I was using Validator in function
use Illuminate\Support\Facades\Validator;
and it worked like a charm.
In my case I just misspelled required a few times.
Laravel Version:5.3
PHP Version: 7.0
Database Driver & Version: MySQL 5.7
Description:
I'm running into this problem when trying to set the sender (not to) and I end up getting an error that looks like this
Symfony\Component\Debug\Exception\FatalThrowableError: [] operator not
supported for strings in
C:\wamp\www\enterprise\vendor\laravel\framework\src\Illuminate\Mail\Mailable.php:384
even though I'm entering an email string It is conflicting with the system email address that I have setup in mail.php.
Nowhere else in the system do I get errors when trying to set email to send from a different email address. I'm trying to send it from the authorized user email
So, in my mailable class, I'm using
public function build()
{
return $this->from(Auth::user()->email)
} ->view('mailbox.sendmail');
But in my mail.php
'from' => [
'address' => 'no-reply#swellsystem.com',
'name' => 'Swell Systems',
],
What is the solution?
This is my Mailable -- UserEmail class. I'm using it to send queued user emails. I have a few dependencies I'm getting from a $request
<?php
namespace App\Mail;
use Auth;
use DB;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class UserEmail extends Mailable
{
use Queueable, SerializesModels;
public $from, $subject, $content;
/**
* Create a new message instance.
*
* #return void
*/
public function __construct($from, $subject, $content)
{
//
$this->from = $from;
$this->subject = $subject;
$this->content = $content;
}
/**
* Build the message.
*
* #return $this
*/
public function build()
{
return $this->from($this->from)
->view('mailbox.sendmail')
->subject('Subject:' . $this->subject)
->with(['body' => $this->content])
}
I call it from a controller
namespace App\Http\Controllers;
use App\Mail\UserEmail;
use Auth;
use Mail;
$from = Auth::user()->email;
$subject = $request->input( 'subject' );
$content = $request->input( 'content' );
Mail::to($request->to)->later($when, (new UserEmail($from, $subject, $content))->onQueue('emails'));
This is the exception given it throws in more detail
Symfony\Component\Debug\Exception\FatalThrowableError: [] operator not
supported for strings in
C:\wamp\www\enterprise\vendor\laravel\framework\src\Illuminate\Mail\Mailable.php:384
Stack trace
1 .
C:\wamp\www\enterprise\vendor\laravel\framework\src\Illuminate\Mail\Mailable.php(312):
Illuminate\Mail\Mailable->setAddress('nmorgan#designl...', NULL,
'from') 2 . C:\wamp\www\enterprise\app\Mail\UserEmail.php(51):
Illuminate\Mail\Mailable->from('nmorgan#designl...')
--[internal function]: App\Mail\UserEmail->build() 3 . C:\wamp\www\enterprise\vendor\laravel\framework\src\Illuminate\Container\Container.php(508):
call_user
If I comment out from in the class the email is sent from the system(mail.php). Otherwise, it throws the error
Would it have to do with anything in my setup? Is there something I am missing.
Mail.php
'from' => [
'address' => 'no-reply#example.com',
'name' => 'System',
],
I found this posted 9 months ago on Laravel.io forum but I don't have a message variable.
<https://laravel.io/forum/10-05-2016-mailablephp-line-382-operator-not-supported-for-strings>
I'm positive that $this->from or Auth::user()->email is definitely a string.. I dumped it and it is "emal#user.com" but I removed it all together and put 'name#example.com' and got the same error
fixed it by removing from in app.php and setting from in every mail
I don't know why my Extension throws this error. Because other extensions like dd_googlesitemap use it in same way as me and this extension do not throw this error.
What am I doing wrong with my $pageId param:
/**
* Creates a link to a single page
*
* #param array $pageId Page ID
* #return string Full URL of the page including host name (escaped)
*/
protected function getPageLink($pageId) {
$conf = array(
'parameter' => $pageId,
'returnLast' => 'url',
);
$link = htmlspecialchars($this->cObj->typoLink('', $conf));
return GeneralUtility::locationHeaderUrl($link);
}
And this is the error output:
Call to a member function getPage_noCheck() on string
It is the method detectLinkTypeFromLinkParameter on line 6364.
Why do I get this error?
This error appears because the $GLOBAL['TSFE'] isnĀ“t initialized at the time I try to use it. After initialization it throws no more errors and works well.
Update:
For those who are still searching for this solution and still using typo3 7.6:
Search for the method initTSFE where it is defined on line 208 (this is the method to init the "TSFE") and where it is initialized on line 94 before getPageLink method
Here the link to the file https://ideone.com/f4TGMm
can you cast your pageUid to int like this
$conf = array(
'parameter' => (int)$pageId,
'returnLast' => 'url',
);
I want to achieve the following:
devices > Controller#devices
devices/{id} > Controller#devices
Is this possible with Laravel ? I'm trying to map a domotic box with an android application ImperiHome, and they expect me to have the same route for devices list and for any device action.
So far I've tried this:
Route::get('devices/{deviceId}/action/{actionName}/{actionParam?}', 'DomoticzController#devices');
Route::get('devices', 'DomoticzController#devices');
But I cannot retrieve the argument when I call the devices/id url
Ok, so to solve the php strict standard error I just splitted the routes to two methods as follows:
routes.php
Route::get('devices/{deviceId}/action/{actionName}/{actionParam?}', 'DomoticzController#device');
Route::get('devices', 'DomoticzController#devices');
Route::get('rooms', 'DomoticzController#rooms');
//Route::get('action_ret', 'DomoticzController#action_ret');
Route::get('system', 'DomoticzController#system');
Route::get('/', 'DomoticzController#system');
DomoticzController.php
/**
* Call for an action on the device identified by $deviceId.
* #return string Json formated action status.
*/
public function device($deviceId, $actionName, $actionParam = null)
{
$client = $this->getClient();
$request = $client->getClient()->createRequest('GET', get_url("json.htm?type=command¶m={$actionName}&idx={$deviceId}}&switchcmd=$actionParam"));
$response = $request->send();
$input = $response->json();
// convert to app format
$output = array('success' => ('OK' === $input['status'] ? true : false), 'errormsg' => ('ERR' === $input['status'] ? 'An error occured' : ''));
return Response::json($output);
}
/**
* Retrieve the list of the available devices.
* #return string Json formatted devices list.
*/
public function devices()
{
$client = $this->getClient();
$request = $client->getClient()->createRequest('GET', get_url('json.htm?type=devices&used=true'));
$response = $request->send();
$input = $response->json();
// convert to app format
$output = new stdClass();
$output->devices = array();
foreach ($input['result'] as $device) {
$output->devices[] = array (
'id' => $device['idx'],
'name' => $device['Name'],
'type' => 'DevSwitch',
'room' => null,
'params' => array(),
);
}
return Response::json($output);
}
maybe there is a better way to solve this, I would be glad to hear it.
If you let both routes use the same controller action, you need to make the parameters optional in the controller I think.
Try this public function device($deviceId = null, $actionName = null, $actionParam = null) and see if you still get the PHP strict error.
You can not have a route without parameters be redirected to a controller action that expects parameters. You can, on the other hand, make a route with parameters be redirected to a controller action with optional parameters (this does not mean that your route parameters need to be optional).
Is there any more or less standard way to specify a route that would create URL's with explicitly specified scheme?
I've tried the solution specified here but it's not excellent for me for several reasons:
It doesn't support base url request property. Actually rewrite router ignores it when URL scheme is specified explicitly.
It's needed to specify separate static route for each scheme-dependent URL (it's not possible to chain module route with hostname route because of base url is ignored).
It's needed to determine HTTP_HOST manually upon router initialization in bootstrap as long as request object is not present within FrontController yet.
Use a combination of the ServerUrl and Url view helpers to construct your URLs, eg (view context)
<?php $this->getHelper('ServerUrl')->setScheme('https') ?>
...
<a href="<?php echo $this->serverUrl($this->url(array(
'url' => 'params'), 'route', $reset, $encode)) ?>">My Link</a>
You can write your own custom View helper for composing an URL. Take a look at the http://www.evilprofessor.co.uk/239-creating-url-in-zend-custom-view-helper/
<?php
class Pro_View_Helper_LinksUrl
extends Zend_View_Helper_Abstract
{
/**
* Returns link category URL
*
* #param string $https
* #param string $module
* #param string $controller
* #param string $action
* #return string Url-FQDN
*/
public function linksUrl($https = false, $module = 'www',
$controller = 'links', $action = 'index')
{
$router = Zend_Controller_Front::getInstance()->getRouter();
$urlParts = $router->assemble(array(
'module' => $module,
'controller' => $controller,
'action' => $action,
), 'www-index');
$FQDN = (($https) ? "https://" : "http://") . $_SERVER["HTTP_HOST"] . $urlParts;
return $FQDN;
}
}