没有 PHP 经验的人应该使用 CakePHP 或 Symfony 这样的框架吗?

发布于 2024-09-14 03:29:11 字数 104 浏览 5 评论 0原文

我有一个简单的网站需要开发,并且想边学习 PHP。我希望该网站安全、可扩展且易于维护。我应该同时学习框架和PHP吗?如果我构建一个框架,就会有很多不熟悉的代码在起作用。您会说这会增加安全风险吗?

I have a simple site to develop and would like to learn PHP as I go. I want the site to be secure, scalable, and easy to maintain. Should I learn a framework and PHP simultaneously? If I build off of a framework there will be lots of unfamiliar code in play. Would you say this increases security risks?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

寄离 2024-09-21 03:29:11

使用框架不会妨碍您学习 PHP,并且使用已建立的框架将降低安全风险,因为您将处理经过良好测试的代码来处理常见任务。

目前大多数 PHP 框架的核心都是这个简单的三步工作流程

  1. 通过中央引导程序 index.php 文件请求和路由 URL

  2. URL 名称用于派生类名和方法名称(以及操作方法)。这是您的主要入口点,也是您开始编写 PHP 来处理请求的地方

  3. 在此方法结束时,控制权将移交给视图模板,该模板可以访问您在第二步中设置的某些值。

选择一个框架,了解它如何执行上述操作,然后在操作方法和视图模板中编写您想要的任何类型的 PHP。

是的,还会有很多其他 PHP 框架代码在起作用,但您永远不必查看它们。

是的,该框架将具有多种功能和/或处理事物的“首选”方式,但您只需要使用那些您立即理解的功能即可。

当您开始注意到丑陋、无聊或不安全的代码模式时,请再次查看框架功能。通常在“做错事”之后,您会深入了解为什么框架代码以特定方式执行某些操作,并且您会很乐意移交责任(我会说 ActiveRecord 样式模型与 SQL 代码这里是一个大问题)

当您开始使用框架提供的面向对象的系统时,您将开始对它们如何做某些事情感兴趣,然后您可以开始研究核心框架代码。

There's nothing about using a framework that will impede you learning PHP, and using an established framework will reduce the security risk, as you'll be dealing with well tested code for handling common tasks.

At the core of most of the PHP frameworks in play these days is this simple three step workflow

  1. The URL is requested and routed through a central bootstrap index.php file

  2. The URL name is used to derive a classname and a method name (and action method). This is your main entry point and where you start writing PHP to handle the request

  3. At the end of this method, control is handed over to a view template, which has access to certain values you set in step two.

Pick a framework, learn how it does the above, and then write any kind of PHP you want in the action method and the view template.

Yes, there will be a lot of other PHP framework code in play, but you never have to look at it.

Yes, the framework will have a multitude of features and/or a "preferred" way for handling things, but you only need to use those you instantly understand.

When you start noticing patterns of ugly, boring, or insecure code, take a look at the framework features again. More often than not after "doing it wrong" you'll get insights as to why the framework code did something in a particular way and you'll be happy to hand off the responsibility (I'd say ActiveRecord style models vs. SQL code is a big one here)

As you start using the objet oriented systems the framework provides you'll start to get interested in how they're doing certain things, and then you can start poking at the core framework code.

一江春梦 2024-09-21 03:29:11

绝对地。框架将为您完成所有样板代码,为您提供更高级别的抽象。您可能会更容易编写代码,而无需处理 PHP 的一些特性。

任何半像样的框架也会解决安全问题,因此,如果您是该语言的新手,那么您在该框架上编写的应用程序很可能会比您从头开始编写的应用程序更安全。

Absolutely. Frameworks will do all the boilerplate code for you, providing you a higher level of abstraction. It will probably be easier for you to code without dealing with some of PHP's idiosyncrasies.

Any half decent framework will also address security issues, so if you are new to the language, chances are your app written on the framework will be safer than the one you write from scratch.

无尽的现实 2024-09-21 03:29:11

我不建议新手开发人员从框架开始。如果您对其他OOP语言有丰富的经验,那么应该没有问题。但在考虑使用框架之前,您至少应该了解基础知识(例如语法)。

I wouldn't recommend starting with a framework to beginning developers. If you've got a lot of experience with other OOP languages, there shouldn't be a problem. But you should at least know the basics (syntax e.g.) before even thinking about using frameworks.

℉絮湮 2024-09-21 03:29:11

我想说这取决于你之前的经验。并不是 PHP 本身会让人分心,而是它所在的 Web 服务器环境可能会让人分心。如果您已经熟悉 HTTP 请求生命周期,并且以与 PHP 类似的无状态方式编写了 Web 应用程序,那么直接使用框架应该不会有大问题。

如果您来自“有状态”背景或根本没有背景,那么框架提供的抽象可能会成为问题。在框架从您那里抽象出详细信息之前,您至少应该知道如何在纯 PHP 中处理会话、cookie、标头、$_POST 等。另请参阅我之前的答案。

I would say it depends on your prior experience. It's not so much PHP itself, but the web server environment it lives in that can be distracting. If you're already familiar with the HTTP request lifecycle and have written web applications in a similar stateless fashion as you do with PHP, you shouldn't have a big problem jumping right into using a framework.

If you come from a "stateful" background or no background at all though, the abstractions a framework offers can become a problem. You should at least know how to handle sessions, cookies, headers, $_POST and the like in plain PHP before having the details abstracted away from you by a framework. Also see this previous answer of mine.

Bonjour°[大白 2024-09-21 03:29:11

我认为,如果您对创建安全系统的能力没有信心(特别是对于身份验证之类的事情),那么最大限度地减少您正在编写的自定义代码的数量可能是一件好事。因此,我认为以这种方式使用 Web 框架会对您有利。它还可以让您熟悉语言的核心,而不必担心外围问题。

I think minimising the amount of custom code you are writing is probably a good thing if you are not confident in your ability to create secure systems (particularly for things like authentication). As a result, I think using a web framework in this way would be to your advantage. It will also allow you to familiarise yourself with the core of the langauge without worrying about peripheral concerns.

鲸落 2024-09-21 03:29:11

我见过一些人(拥有丰富的 OOP 知识)同时学习 PHP 和 symfony,没有任何困难。

事实上,从面向对象语言转向PHP只是学习一些概念性的东西以及PHP本身的语法和API。

I have seen a few people (with a big previous OOP knowledge) to learn PHP and symfony simultaneously without difficulties.

In fact, moving from PHP from an object oriented language is just learn a few conceptual things and the syntax and API of PHP itself.

笔芯 2024-09-21 03:29:11

在我看来,在学习语言的同时学习框架并没有什么错。已经有相当多的情况不可避免地需要这种情况。例如,大多数学习 Objective-C 的人同时学习 Cocoa 框架,大多数 C# 程序员会同时学习 .Net,甚至 JDK 也应该被认为是与 Java 语言一起学习的框架。无论如何,我之前学习了 Symfony 框架,但几乎没有 PHP 经验。

In my opinion, there's nothing wrong with learning a framework at the same time as you are learning a language. There are already a fair amount of situations where this is the case by necessity. For example, most people learning Objective-C learn the Cocoa frameworks at the same time, most C# programmers will learn .Net along with it, even the JDK should be considered a framework which you learn along with the Java language. And for what it's worth, I learned the Symfony framework with very little PHP experience beforehand.

软糖 2024-09-21 03:29:11

我建议您从 w3schools.com 上的 PHP turorial 开始。它简短而清晰。您可以在一到两个小时内学习所有必要的基础知识。为了理解任何框架,你都需要它。然后研究第一个CakePHP 食谱中的第二章 并使用其 教程。其余方面我同意艾伦·斯托姆的观点。

I would advice you to start with PHP turorial on w3schools.com. It is short and clear. You can learn all the necessary basics in one-two hours. In order to understand any framework you will need that. Then study the first and the second chapter from CakePHP cookbook and create your first CakePHP applications using their tutorials. On the rest I agree with Alan Storm.

我纯我任性 2024-09-21 03:29:11

开始使用 PHP 框架还取决于您是否有一些编程经验,如果有,是哪种经验。

如果您对其他一些编程语言(如java、c)感到困惑,那么在创建网站的同时学习php框架可能不会太困难。

您将遇到的几乎所有 PHP 框架都使用 MVC 设计模式 - 如果您了解 MVC 的基础知识,如果您已经在其他编程语言中实现或掌握了设计模式的要点,那么开始使用 PHP 框架将会非常容易。

您选择的 PHP 框架也将是决定因素。如果您使用像 Codeigniter、Yii 甚至 CakePHP 这样的 PHP 框架,这些框架的学习曲线相对较小,您会发现 PHP 为您铺平了道路。尽管如果选择像 Symfony、Zend 这样的框架,你可能会因为花太多时间做简单的事情而感到沮丧,进而毁掉你的项目。

至于安全风险部分,我上面提到的所有框架以及其他一些我没有提到的框架,都花了足够的时间在台上,将安全风险压垮了。

希望这有助于做出决定。

Getting started with a framework in PHP, also depends on the fact whether you have some prior programming experience and if yes, what kind of.

If you have muddled in some other programming languages like java, c, learning a php framework simultaneously while creating your website might not be too difficult.

Almost all of the PHP frameworks you will encounter use the MVC design pattern - if you understand the basics of MVC, if you have implemented or have gist of design patterns in other programming languages, then it will be quite easy starting with PHP frameworks.

Also your choice of PHP framework will be the deciding factor. If you employ PHP frameworks like Codeigniter, Yii, maybe even CakePHP which have comparatively smaller learning curves, you will find your path wellpaved for you in PHP. Although if choose some framework like Symfony, Zend - you might get frustrated in taking too much time in doing simple things, in turn blowing up your project.

As for the part about security risk, all of the frameworks I mentioned above and some others I have not mentioned, have spent enough time on the stage to have squashed the security risks.

Hope this helps in deciding.

怪我鬧 2024-09-21 03:29:11

尽管我是框架的粉丝,但我同意上面的一些其他评论。从框架开始可能会非常令人困惑,特别是如果您没有模型视图控制器 (MVC) 面向对象编程 (OOP) 理论的经验。

说实话,我见过的未完成的框架项目比没有框架构建的应用程序还要多。如果您的应用程序是用一些笨重的 PHP 编写的,并且该应用程序取得了成功,那么您可以雇用必要的资源来迁移到框架,并将其开发为能够承受大量使用并有效利用资源。

我的建议是先掌握 PHP,然后再转向框架。我关于这一点的最后一点是,许多框架也有缺陷 - 因此根据您的应用程序需求,应用错误的框架可能会导致它陷入困境。

作为一个在没有使用 PHP 框架的情况下成功发布了几个企业应用程序的人,我只付出了 2 美分。

Although I'm a fan of frameworks, I agree with some of the other comments above. Starting with a framework can be pretty confusing, especially if you're not experienced in the theory of Model View Controller (MVC) object oriented programming (OOP).

Truth be told, I've seen a lot more unfinished framework projects in my day than apps built without a framework. If your application is written with some clunky PHP and the application takes off, then you can hire the necessary resources to move to a framework and get it developed to withstand a lot of usage and utilize resources effectively.

My advice would be to master PHP first, then move to frameworks. My last note on this, many frameworks have flaws as well - so depending on your application needs, applying the wrong framework could drive it into the ground.

Just my 2 cents as a guy that has released a couple of enterprise apps successfully - without using a PHP framework.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文