Answer the question
In order to leave comments, you need to log in
Is it possible and necessary to pass a JSON object from PHP to ANGULAR in a custom HTTP header?
Hello.
I apologize for the possibly stupid question, but still. Passing data from PHP to angular is a pain in the ass unless you're working with SPA . I have twig templates. At the moment I use my directive to transfer data from PHP to scope (ng-init also considered). There is no desire to make many requests to obtain data. So I thought that if you pass a JSON object with data for a specific page in your X-Custom-Header header, and read them and transfer them to scope. I would like to hear your opinions, maybe you know other ways to pass data from a PHP template to angular.
----
Guys, let's go! I didn't know that JS can't get the titles of the initial page.
Answer the question
In order to leave comments, you need to log in
This is definitely not according to REST and, accordingly, there will be problems with caching, besides, it is not known how proxy servers will behave with such headers, you can hit the limit and the proxy will simply cut them.
All in all, it's a bad idea in my opinion.
Easy.
<!-- тег должен лежать до загрузки скриптов приложения -->
<script>
window.userInfo = <?= json_encode(Session::get('user')); ?>;
</script>
<!-- внутри приложения -->
<script>
app.config(function($provide) {
$provide.constant('userInfo', angular.copy(window.userInfo));
});
</script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question