La dirección y el marco de argumentos [cerrado]

How should look the address and the arguments in the framework?

Do you write:

site.com/controller/method?arg=1&arg=2

¿Es bueno?

Do better the record:

site.com/controller/method/arg/1/arg2/2

I would ask for example, as is the intermediate frameworks

preguntado el 08 de noviembre de 11 a las 11:11

Are you asking how a specific framework handles its URLs, or are you implementing a new framework and ask which way is better? -

3 Respuestas

The framework I'm most experienced with (CodeIgniter) mainly uses this approach, calling it "url segmentation"

site.com/index.php/controller/method/arg/1/arg2/2

The URL is retrieved through $_SERVER array and then exploded ("/") and a master class (which acts as an entry point) assigns the different chunks to the competend handler (first segment to controller, second to a method, the rest to the said method as an array of parameters; you might use function_get_args() there, for example, to retrieve them)

Another common options, and easier to implement, is using query strings

site.com/?c=controller&m=method&arg1=arg1&arg2=arg2&arg3=2

which you can easily retrieve with the $_GET array and rewrite in in .htaccess to look "Prettier". That's how pretty urls are there for :)

respondido 08 nov., 11:16

Actually this should not play a role for you. However a framework does this, it should offer you access to both controllers and arguments.

El primer ejemplo

site.com/controller/method?arg=1&arg=2

has the benefit that you can better distinguish between the command controller/method and it's arguments arg=1&arg=2 so this looks more affine to HTTP here.

Some will tell you that these URLs are not SEO friendly, but we see more and more search engines that make use of the semantics here, so the full story is that both variants are SEO friendly and only if you mix both concepts, you will gain maximum control for SEO.

In any case should a framework allow multiple ways so you're able to make use of what you think is most useful to your needs. That's normally called routing.

respondido 08 nov., 11:16

Well, generally frameworks has url pattern like

somesite.com/controllerName/actionName/arg1/arg2/.../argN

Esta es una mejor manera

respondido 08 nov., 11:15

ok but i cant get arguments in $_GET - zyeu

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.