Picture M-V data flow. $tmp_imgpath=/srv/disk16/3266814/www/phporacle.eu5.net/zinc/img/img_big/mvc_M_V_data_flow.jpg
$tmp_imgurlrel=/zinc/img/img_big/mvc_M_V_data_flow.jpg Edit post data in database table row ⟩⟩

Category: B12phpfw & Written by ss On 2019-10-18 15:10:29

Summary: WHY Nobody made good (not to simple) tutorial about PHP menu & CRUD code skeleton ? Especially for each module in own folder like Oracle forms .fmb-s there is (almost) nothing to find in learning sources.

1. PHP menu & CRUD code skeleton (I named it B12phpfw)

see https://github.com/slavkoss/fwphp/blob/master/readme.md ([web server root dir. path]/readme.md, [web server root dir. path]=J:/awww/www).

mvc_M_C_V_data_flow_Laravel.jpg

Picture 01-1. Laravel CODE STRUCTURE (code flow ee signals flow) : 1, 2 and 3 are routing code snippets (odsječci) all 3 in same script, or separate scripts, or separate classes scripts.

In B12phpfw :

  1. ROUTING USING KEY-VALUES is in shared (global) class [web server root dir. path]/zinc/Config_allsites.php
  2. DISPATCHING USING Home_ctr CLASS METHODS is in [module dir path]Home_ctr.php ee in [web server root dir. path]/fwphp\glomodul\blog\Home_ctr.php Dispatching is based on Mini3 PHP fw.


mvc_M_C_V.jpg

Picture 01-2. M-C-V data flow (Laravel) : M-C-V data flow is usual in PHP world, not in JS, Blazor, Oracle Forms .fmb-s...

Controller instantiates M and includes V (instantiates V if V is class) and pushes M data to V.

I do not see advantages compared to M-V data flow. Disadvantages are :

  1. for pagination M-V data flow is only possible solution - If we have user's interactions (events) eg filter displayed rows (pagination is also filtering)
  2. C is fat in large modules (lot of code). (C in my msg - blog module - M-V data flow - has lot of code, but code is very simple, may be small but clear code is better than short unclear code.)




mvc_M_V_data_flow.jpg

Picture 02-1. M-V data flow (original MVC idea) : V pulls data from M = cRud actions - only R using DAO classes : module's Tbl_crud.php and shared Db_allsites.

Model code is most complicated. C and V code can be standardized, M only partially : cc, rr, uu, dd methods for all tables but business logic in M code can not be standardized.

User's events are handled in Controller class. Code (signal) flow :

  1. C assigns user's orders in URL query string to variables (in B12phpfw : var, varvalue pairs) telling V what user wants
  2. C then includes V (not showed in picture above)
  3. V pulls data from M according C variables (user's orders in URL )
  4. V also may call C method for some state changes in DB ordered by user in URL, eg table row updates like approve user comment
  5. V script may contain class but I do not see need for view classes because view script is included in Home_ctr class and can use $this to access methods and attributes in whole class hierarchy : Home_ctr, Config_allsites, Db_allsites. If we do not need CRUD (user events) than we do not need this class hierarchy, meaning that simple coding like in mnu and mkd modules suffices - no need for CRUD code skeleton B12phpfw.


mvc_M_V_data_flow_MVC_3tier_DAO_abstract_interface.jpg

Picture 02-2. M-V data flow (original MVC idea)

Controller includes (instantiates) V which instantiates DAO class (in B12phpfw it is [web server root dir. path]/fwphp/glomodul\user/Tbl_crud.php - same named Tbl_crud.php is in all modules dirs) :

Data access object (DAO) pattern provides an abstract (public) interface (Config_allsites.php) to some DB or other persistence mechanism (implementation of DAO Db_allsites).

By mapping app calls in Tbl_crud.php to persistence layer Db_allsites, DAO is not exposing DB details, it is isolation which supports single responsibility principle.




mvc_M_V_and_M_C_V_data_flow.jpg

Picture 03. M-V and M-C-V data flow compared - both are ok.

  1. M-V data flow : V instantiates M and pulls data from M
  2. M-C-V data flow : C instantiates M and inc. or instatiates V , pulls data from M and pushes data object to V (or array, or best cursor which V reads row by row).

I prefer M-V which is also M-C data flow (if C manipulates persistence layer data eg in DB, web service, csv file... = CRUD actions - all four: C,R,U and D.





Comments

ss

2019-11-03 14:54:36

##### eeeeee wwwwwwww 3 33333333333333 33333333 333########


ss

2019-10-20 21:06:44

ssssssssssssssssssssssssssss ssssssssssssssss ssssssssssss


Nick Walter

2019-01-12 19:45:19

great post


Malik G

2019-01-12 10:19:59

جا سو Centaurus راجہ جی


Share your thoughts about this post
Real life site code examples.

1. Teme (posts categories filter)

ALL    111     B12phpfw     Fitness     Movies     News     Politics     Science     Sports     Technology     World    

2. Recent posts (date filter)

Politics    
B12phpfw    
001. Menu_CRUD.txt

2019-10-18 15:10:29


Technology    
HTML5_CSS3.txt

2019-10-12 12:20:29


B12phpfw    
altervista013.txt

2019-03-16 12:20:29


B12phpfw    
altervista012.txt

2019-02-24 12:20:29


B12phpfw    
altervista011.txt

2018-05-29 08:20:29


B12phpfw    
altervista001c.txt

2017-09-27 12:20:29


B12phpfw    
altervista001b.txt

2017-09-13 12:20:29


B12phpfw    
altervista002a.txt

2017-05-27 12:20:29


B12phpfw    
altervista001a.txt

2016-10-26 12:20:29



      _.-'''''-._
    .'  _     _  '.
   /   (o)   (o)   \
  |        ©        |
  | Slavko Srakočić |
   \  '. Zagreb.'  /
    '.  ''---''  .'
      '-._____.-' 
    
/srv/disk16/3266814/www/phporacle.eu5.net/fwphp/glomodul/blog/home_side_area.php

PHP_OS=Linux, php_uname()=Linux f21.runhosting.com 5.10.138kvmcap #1 SMP Fri Aug 26 07:32:35 UTC 2022 x86_64
$_SERVER['DOCUMENT_ROOT']=/home/www/phporacle.eu5.net
$_SERVER['REQUEST_URI']=/fwphp/glomodul/blog/?i/read_post/id/54
$_SERVER['QUERY_STRING']=i/read_post/id/54
$_SERVER['HTTP_HOST']=phporacle.eu5.net
~~~~~~~~~/srv/disk16/3266814/www/phporacle.eu5.net/zinc/ftr.php() , line 78 SAYS:
OS web server doc root $this->p p 1->wsroot_path=/srv/disk16/3266814/www/phporacle.eu5.net/
Same web server doc root as URL $this->p p1->wsroot_url=http://phporacle.eu5.net/
Module property pallete like in Oracle Forms :
$this->p p 1
=stdClass Object ( [dbg] => 1 [stack_trace] => Array ( [0] => Array ( [0] => /srv/disk16/3266814/www/phporacle.eu5.net/fwphp/glomodul/blog/index.php, lin=18 ) ) [module_towsroot] => ../../../ [module_version] => 6.0.4.0 Msg [vendor_namesp_prefix] => B12phpfw [module_path_arr] => Array ( [0] => /srv/disk16/3266814/www/phporacle.eu5.net/fwphp/glomodul/blog/ [1] => /srv/disk16/3266814/www/phporacle.eu5.net/zinc/ [2] => /srv/disk16/3266814/www/phporacle.eu5.net/fwphp/glomodul/user/ [3] => /srv/disk16/3266814/www/phporacle.eu5.net/fwphp/glomodul/post_category/ [4] => /srv/disk16/3266814/www/phporacle.eu5.net/fwphp/glomodul/post/ [5] => /srv/disk16/3266814/www/phporacle.eu5.net/fwphp/glomodul/post_comment/ ) [uriq] => stdClass Object ( [i] => read_post [id] => 54 ) [F O R $_S E S ARR. (D B S H E M A...)] => ~~~~~~~~~~~~~~~~~ [cncts] => stdClass Object ( ) [states] => stdClass Object ( ) [A D R E S S E S in Config_allsites.php] => ~~~~~~~~~~~~~~~~ [wsroot_path] => /srv/disk16/3266814/www/phporacle.eu5.net/ [wsroot_url] => http://phporacle.eu5.net/ [imgrel_path] => zinc/img/ [module_path] => /srv/disk16/3266814/www/phporacle.eu5.net/fwphp/glomodul/blog/ [uri_arr] => Array ( [0] => /fwphp/glomodul/blog/ [1] => i/read_post/id/54 ) [module_relpath] => fwphp/glomodul/blog [module_url] => http://phporacle.eu5.net/fwphp/glomodul/blog/ [uri_qrystring_arr] => Array ( [0] => i [1] => read_post [2] => id [3] => 54 ) [ROUTES (LINKS) IN M O D U L E CTR Home_ctr.php] => ~~~~~~~~~~~~~~~~~ [PP1_ MODULE] => ~~~~~in view script eg href = $pp1->login~~~~~ [loginfrm] => ?i/loginfrm/ [login] => ?i/login/ [logout] => ?i/logout/r/i|loginfrm| [del_row] => ?i/del_row_do/ [filter_page] => ?p/ [dashboard] => ?i/dashboard/ [admins] => ?i/admins/ [read_user] => ?i/read_user/ [upd_user_loggedin] => ?i/upd_user_loggedin/ [categories] => ?i/categories/ [posts] => ?i/posts/ [filter_postcateg] => ?i/filter_postcateg/c/ [addnewpost] => ?i/addnewpost/ [read_post] => ?i/read_post/ [editpost] => ?i/editpost/ [edmkdpost] => ?i/edmkdpost/ [readmkdpost] => ?i/readmkdpost/ [comments] => ?i/comments/ [upd_comment_stat] => ?i/upd_comment_stat/ [kalendar] => ?i/kalendar/ [about_us] => ?i/about/ [contact_us] => ?i/contact/ [features] => ?i/features/ ) $_ GET=Array ( [i/read_post/id/54] => ) $_POST=Array ( ) $_SESSION=Array ( )