简体   繁体   English

基于url参数的动态php类生成

[英]Dynamic php class generation based on url parameters

I have an image generating class and a number of sub classes inherited from this. 我有一个图像生成类和许多继承自此的子类。 Each sub class generates a different image. 每个子类生成一个不同的图像。 I would like to pass the class to generate (or some sort of identifier) in the URL. 我想传递该类以在URL中生成(或某种标识符)。 EG: www.mysite.com/image.php?class=image002 In image.php I could read the class name from the URL, compare this to my database to find the class, then include that class file and generate. EG:www.mysite.com/image.php?class=image002在image.php中,我可以从URL中读取类名称,将其与数据库进行比较以找到该类,然后包含该类文件并生成。 I feel that this is not the correct way of doing it. 我觉得这不是正确的方法。 Are there better ways? 有更好的方法吗?

Apparently there is nothing wrong with your passing values into url that way especially if these image names are unique and are not sensitive data. 显然,以这种方式将值传递到url并没有什么问题,特别是如果这些图像名称是唯一的并且不是敏感数据。 unique so that you dont execute the same class with two different images. 唯一的,这样您就不会用两个不同的图像执行同一类。 but you could just append/prepend a random string to the image value. 但您可以在图像值后面附加/添加一个随机字符串。 also as hamza said hope they aren't php classes 就像hamza所说的,希望他们不是php类

I am going to go with this answer: 我将使用以下答案:

"Instantiate a class from a variable in PHP?" “从PHP中的变量实例化一个类吗?”

instantiate a class from a variable in PHP? 从PHP中的变量实例化一个类?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM