model view controller - How to Change link (nameOfController?a=1&b=5&c=20&d=30) in Custom PHP MVC -


i'm trying retrieve data database of values in link uisng method... , working custom php mvc..

since im still beginner, don't know access data send form in page 1 form in page 2..

this regular way.

example

page1.php

<form method="get" action="<?php echo url"./page2.".php ;?> ">     <select name="a">         <option value="1">option 1</option>         <option value="2">option 2</option>     </select>     <select name="b">         <option value="1">option 1</option>         <option value="2">option 2</option>     </select>     <select name="c">         <option value="1">option 1</option>         <option value="2">option 2</option>    </select>     <input type="submit" value="continue"> </form> 

when submitting form page 2

page2.php?a=1&b=5&c=20&d=30

    <select name="a">         <option value="1" <?php echo($_get['a']=='1')? 'selected': '';?>>option 1</option>         <option value="2" <?php echo($_get['a']=='2')? 'selected': '';?>>option 2</option>     </select>     <select name="b">         <option value="1" <?php echo($_get['b']=='1')? 'selected': '';?>>option 1</option>         <option value="2" <?php echo($_get['b']=='2')? 'selected': '';?>>option 2</option>     </select>     <select name="c">         <option value="1" <?php echo($_get['c']=='1')? 'selected': '';?>>option 1</option>         <option value="2" <?php echo($_get['a']=='2')? 'selected': '';?>>option 2</option>    </select> </form> 

how change method mvc method : ..../nameofcontroller/.......

nb: know basis of mvc.

i don't think can in native way can accomplish such things couple of works :

since file "nameofcontroller" not exist in application, you'll need trick bit , i'll try describe possible how of mvc frameworks handle such request :

  • there "main" file catch every single request , allow framework interprete it. example, it's called "index.php" in zend framework or "app.php" in symfony.

  • an ".htaccess" file rules redirect every single request want main file main file able analyze them. can specify in rules don't want apache redirect requests leading real resources on server (images, css files, etc.)

  • then, there looks "router"/"dispatcher" module call specific controller , specific method according shape of request , of rules you've decided.

it's declare own rules , want app (folders containing controllers, name of traditional methods of controllers, etc.)

i hope you, sorry bad english


edit : here example :

let's imagine have .htaccess file. i'll take symfony example on purpose :

# use front controller index file. serves fallback solution when # every other rewrite/redirect fails (e.g. in aliased environment without # mod_rewrite). additionally, reduces matching process # start page (path "/") because otherwise apache apply rewriting rules # each configured directoryindex file (e.g. index.php, index.html, index.pl). directoryindex app.php  # disabling multiviews prevents unwanted negotiation, e.g. "/app" should not resolve # front controller "/app.php" rewritten "/app.php/app". <ifmodule mod_negotiation.c>     options -multiviews </ifmodule>  <ifmodule mod_rewrite.c>     rewriteengine on      # determine rewritebase automatically , set environment variable.     # if using apache aliases mass virtual hosting or installed     # project in subdirectory, base path prepended allow proper     # resolution of app.php file , redirect correct uri.     # work in environments without path prefix well, providing safe, one-size     # fits solution. not need in case, can comment     # following 2 lines eliminate overhead.     rewritecond %{request_uri}::$1 ^(/.+)/(.*)::\2$     rewriterule ^(.*) - [e=base:%1]      # sets http_authorization header removed apache     rewritecond %{http:authorization} .     rewriterule .* - [e=http_authorization:%{http:authorization}]      # redirect uri without front controller prevent duplicate content     # (with , without `/app.php`). redirect on initial     # rewrite apache , not on subsequent cycles. otherwise     # endless redirect loop (request -> rewrite front controller ->     # redirect -> request -> ...).     # in case "too many redirects" error or redirected     # start page because apache not expose redirect_status     # environment variable, have 2 choices:     # - disable feature commenting following 2 lines or     # - use apache >= 2.3.9 , replace l flags end flags , remove     #   following rewritecond (best solution)     rewritecond %{env:redirect_status} ^$     rewriterule ^app\.php(/(.*)|$) %{env:base}/$2 [r=301,l]      # if requested filename exists, serve it.     # want let apache serve files , not directories.     rewritecond %{request_filename} -f     rewriterule .? - [l]      # rewrite other queries front controller.     rewriterule .? %{env:base}/app.php [l] </ifmodule>  <ifmodule !mod_rewrite.c>     <ifmodule mod_alias.c>         # when mod_rewrite not available, instruct temporary redirect of         # start page front controller explicitly website         # , generated links can still used.         redirectmatch 302 ^/$ /app.php/         # redirecttemp cannot used instead     </ifmodule> </ifmodule> 

globally, script redirect every request (except pointing on physicaly existing resources) on file named "app.php". file "app.php" designed starter of application , contains code below :

<?php use symfony\component\classloader\apcclassloader; use symfony\component\httpfoundation\request; $loader = require_once __dir__.'/../app/bootstrap.php.cache'; // enable apc autoloading improve performance. // should change apcclassloader first argument unique prefix // in order prevent cache key conflicts other applications // using apc. /* $apcloader = new apcclassloader(sha1(__file__), $loader); $loader->unregister(); $apcloader->register(true); */ require_once __dir__.'/../app/appkernel.php'; //require_once __dir__.'/../app/appcache.php'; $kernel = new appkernel('prod', false); $kernel->loadclasscache(); //$kernel = new appcache($kernel); // when using httpcache, need call method in front controller instead of relying on configuration parameter //request::enablehttpmethodparameteroverride(); $request = request::createfromglobals(); $response = $kernel->handle($request); $response->send(); $kernel->terminate($request, $response); 

this 1 loads kernel (which code of symfony framework) , tries recompose requests php global variables :

$request = request::createfromglobals(); 

then, kernel handles our request :

$response = $kernel->handle($request); 

which results in response.

we can imagine handle method "analyses" request method (which corresponds http request) , try deduct controller has reach , method should call.

globally, sf app , modules (which can define different parts of website example) designed way : there "src" folder contains "bundles" (modules) , thoses bundles belong own namespace, e.g com\myappbundle\, com\blogbundle\, com\adminbundle\, etc.

each bundle can contain controllers (resulting namespace : com\myappbundle\controller), forms (com\myappbundle\form) , on, , kernel try find correct resource reach. follow psr-4 , psr-0 namespace format.

to know controller can reached specific kind of url, symfony allows define "routes" associate url pattern specific rules.

example of route coming right symfony (.yml file) :

bloc_article_show:     pattern:  /blog/article/{id}/     defaults: { _controller: "commyappbundle:blog:show" }     requirements:         id:  \d+ 

this rule, named "bloc_article_show" custom rule says url match following pattern /blog/article/{id}/ (e.g /blog/article/9/), kernel should dispatch request controller named blogcontroller belongs com\myappbundle\ namespace. once controller reached, method "show" called $id parameter. specify "id" parameter must digit [0-9]+

warning : /bloc/article/ not existing directory/folder ;)

this straight example coming symfony of existing framework pretty similar :) it's define way mvc application catch requests , dispatch them.

hope helpful


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -