yii2 formatting response - yii2 tutorials | part 9

preview_player
Показать описание
The video covers the following topics:

How to return response implicitly and explicitly.
How to change the status code of the response.
How to format the response into JSON or XML.
How to add additional headers to response.
How to properly redirect in controller and outside of the controller.
How to send files as response.

----------------------------------------------------------------------------------
Check my other videos about yii2 framework
----------------------------------------------------------------------------------

Check my Github:

Follow me on social media:
Рекомендации по теме
Комментарии
Автор

I work in a company where 50+ employees are working on Yii2 and first thing I am gonna do in our coming training is sharing your channel let people know about you .
👍

naresh
Автор

i've started learning yii but due to the lack of video i didn't found the good chanel but sir you've covered all the initial things on the framework truly thank you so much

Raezon_
Автор

i love you bro. you save my time . Good Job . lots of Json response on forums, all too many useless ... it's working now thx a lot .

CrazyPandaTuts
Автор

Let me post a comment again as well, keep it coming Zura 🙌🏻 enjoying your explanations!

SB-krki
Автор

Hello zura. Your videos are amazing. They really provide great value and insights. How did you set up phpstorm with the yii code suggestions (hints)? Can we do it in VS code or sublime text?

prasaddiwan
Автор

Great video!
I have been thinking what could be the best way to provide language texts for javascripts.
I think include a generated content from message dir could be enough.
What response should I use?
Return a js file?


return language = '.json_encode($language, JSON_UNESCAPED_UNICODE) .';', 'language.js');
or just a simple echo?

return 'let language = '.json_encode($language) .';';


What do you think master yii? :)


class LanguageController extends Controller
{
private $dir;
private $sourceLanguage;
private $language;

public function init()
{
parent::init();

$this->sourceLanguage = Yii::$app->sourceLanguage;
$this->language = Yii::$app->language;
}

public function actionIndex()
{
$language = $this->loadDir($this->dir . '/' . $this->sourceLanguage . '/');
$language = array_merge($language, $this->loadDir($this->dir . '/' . $this->language . '/'));

return 'let language = '.json_encode($language) .';';
}

public function actionFile(string $file, $code = null)
{
$language = $this->loadFile($this->dir . '/' . $this->sourceLanguage . '/' .$file);
$language = array_merge($language, $this->loadFile($this->dir . '/' . $code ?? $this->language . '/' .$file));

//return language = '.json_encode($language, JSON_UNESCAPED_UNICODE) .';', 'language.js');

return 'let language = '.json_encode($language) .';';
}

private function loadFile(string $path): array
{
$language = array();

$file = $path . '.php';

if (is_file($file)) {
$language = include $file;
}

return $language;
}

private function loadDir(string $dir): array
{
$language = array();
$files = array();

if (is_dir($dir)) {
$files = scandir($dir);
}

foreach ($files as $file) {
if (is_file($dir.'/'.$file)) {
$language[basename($file, '.php')] = include $dir.'/'.$file;
}
}

return $language;
}
}

music-unleashed