dtukyb8095 2015-07-10 15:29
浏览 36

将Smarty PhP应用程序转换为AngularJS

I have a PHP app that uses Smarty. It is not using any standard MVC framework but achieves the same aim as follows:

  • each click that causes a page transition does it by calling a structured URL (akin to REST calls) that is interpreted by Apache rewrite rules (in .htaccess) into specific query parameters attached to the index.php file.

  • the index.php then determines which page or sub-page to load, performs whatever controller logic and then assembles the display info, loads smarty vars and then displays

I read somewhere that it's not advisable to mix front and back end MVC frameworks. I however need to convert the app in as short a timeframe as possible.

The typical combination is to have angular call a PHP REST backend. However I would rather keep all the deep business logic in the back end (not just CRUD actions) but have the PHP send back to my angular the data to be displayed.

I'm pretty new to Angular: is there anything that makes this technically impossible or suboptimal?

  • 写回答

1条回答 默认 最新

  • dongqiao6730 2015-07-10 16:26
    关注

    The typical combination is to have angular call a PHP REST backend.

    Typical, yes. But not absolutely necessary. Your webservice can be structured the way you want.

    However I would rather keep all the deep business logic in the back end (not just CRUD actions) but have the PHP send back to my angular the data to be displayed.

    I might be misinterpreting you but, keeping your business logic in the backend is how it is supposed to be. Rest is not CRUD.


    the index.php then determines which page or sub-page to load, performs whatever controller logic and then assembles the display info, loads smarty vars and then displays

    The problem here is the "controller logic". From what I can gather you're trying to replace a server-side template engine with a client side template engine. That's fine. But AngularJS is not a template engine and there are some key points that might make it a bad choice in your case:

    1. Angular is meant to work as a single page website/app. This means it expects pageflow and view logic, for instance, to be controlled by the client side. By keeping the "controller" logic in the backend, you turn Angular into an extremely inefficient and heavy template engine.

    2. It expects the backend to serve (structured) data, not a "full" view. Sure, nothing stops you from requesting a PHP document. But it kind of defeats the purpose of using angular.

    3. It plays nicely with REST because of its stateless nature. This can be a bit of a challenge since it deviates from the usual PHP setup. The biggest example are logins and PHP sessions.

      Usually, in most PHP setups, a user authenticates through a login form and then the server responds with a cookie, usually containing a PHPSESSID. While the cookie gets passed around, the user stays logged in and the appropriate UI/view/data is displayed. To adapt this logic to AngularJS single page app requires a bit of work. This article might help you


    I'm pretty new to Angular: is there anything that makes this technically impossible or suboptimal?

    In short... impossible no, far from it. suboptimal maybe...


    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置