PHP - Moved: Framework - Routing & Modules Question/help
This topic has been moved to Application Design.
http://www.phpfreaks.com/forums/index.php?topic=332538.0 Similar Tutorialsim tying to design and make a routing system for my mvc framework but im wondering the best way to do this if anyone could help on how the design pattern would be. im thinking i would have a route config file which would contain all the routes for each file routes.config <?php $routes = array('news' => 'news/index'); ?> then the routing class which would get the correct route depeding on the request class and get the dispatch class to load the controller and action? if anyone could help on the best way to do this that would be great...thanks This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=347122.0 This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=324009.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=328743.0 This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=327717.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=322256.0 This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=319964.0 This topic has been moved to Application Frameworks. http://www.phpfreaks.com/forums/index.php?topic=317468.0 hi gang, I just spent the better part of the day trying to find a way modularize my PHP code. I want to execute a php file and load the results into my main php program. I am not looking to include php source code into my prog and then execute it, I want to execute it and load the results into my prog. I know I can do this if I call a php file via apache: using file(http://ww.site.com/blah.php?parms) but is there a way to do it without using http ? The php file is local - in the same directory. I want something like this: $r = something.php?parms... how do I do this? regards, david Okay, so now I need help evolving my Log-In system... Up until now, the only place a user could log-in was on a given Article page if they wanted to add a comment to the Article. To accommodate that feature, I was setting the "Return To Page" only in my "article.php" script like this... Code: [Select] $_SESSION['returnToPage'] = $_SERVER['SCRIPT_NAME'] . '?title=' . $articleTitle; However, now I want to expand things. I'm growing increasingly confused about how to manage where to route people when they long-in?! 1.) Sometimes a user will Log-In and want to return where they were at (e.g. index.php, article1234.php) 2.) Sometimes a user might want to continue down a path (e.g. Checking Out, Registering for a Workshop, Sending a Message) Is there some kind of strategy to handle this? (nothing over complex, but there must be some Best Practices that work?! Debbie Hi I relatively new to MVC and trying to understand it all by coding my own MVC framework. I already have coded my (own variant) MVC application: a router calling controllers each creating CRUD(L)* forms (views) onto separate db tables. Now I want to create a dashboard with multiple forms each modifying a separate database table. I already have the ability for one controller to call another controller ad infinitum. However when I press "modify" on one of the forms I do not know how to route (call the router) to rebuild the dashboard restoring all the other forms (ie other controllers) to the same state they were in when my target form requested a modification. Basically I don't know how to go about routing in a hierarchical or nested MVC framework. Should I design a complex (non-linear tree-like) URL request that captures the state of my dashboard and have a very complex router that can decode it? Should each action be idempotent or should I use state in the session to make the request URL easier? *CRUD(L) a view with different forms for CRUD and L(ist) operations each invling different controller methods. I have tried searching under "HMVC" (but that seems to mean "modules") and "nested MVC" but for both terms I mostly get referred to established frameworks. Cheers GAJ Creating a basic MVC framework. I may confuse myself while asking this, so bare with me if this is confusing for you also... As far as i understand, the URLs are in the following format: www.example.com/controller/method/args My goal here is to not show 'method' in the URL if it's not necessary. For example, www.example.com/contact instead of www.example.com/contact/view. This is OK. I can accomplish this. But problems arise when I want to pass arguments in the URL. Say I have the URL: www.example.com/users <----- this would by default, user the controller 'users' and call default method, 'view'..just list all users. But say i want to view a user.. John. www.example.com/users/john How can I make my script know that 'john' is an argument, and not a method? The only way I can think of this is if I always have a method in the url .. like www.example.com/users/view/username/john As of now, my script breaks up the URL at / and the first element in the array is is the controller. It calls the controller with the other arguments. so www.example.com/users/john. The script would do (simplified) $controller = 'users' $controller = new $controller('john') the 'Users' class would then see if 'john' is a method. If it is, call it, if not, then call the default method (view) with john as argument... but what if I have a method called 'edit' and someone's username is edit? then www.example.com/users/edit would be a problem. So my guestion to you guy is... how do you deal with this issue? If you have www.example.com/users/edit, how do you let the script know that 'edit' is someone's username and now a method to call? Do you pass the method in the url like so www.example.com/users/edit/edit ? Or if you have worked with a framework (Zend, cakePHP, Symfony, CodeIgniter, etc), how does the framework handle it? Ideally, i would like to be able to have www.example.com/users/john instead of www.example.com/users/view/id/john Hi guys, I am developing an MVC application and need some advice about how to set up url routing. Currently I can map a uri to modules/controllers and actions. I though I might leave the routing to last but it seems like that might have been a bad idea. Initially I though I might implement a Zend style routing approach and I still want to do this, but I am lost for thoughs on how I might go about this, I have looked at the zend router classes and understand the principle but cant seem to implement it in my own mvc. So far I have this, $router is an instance of a router class. mapRoute takes a route name and a route object as parameters. The name will be used for convinience. The second parameter takes a route instance which currently takes two parameters, where param1 is a route pattern and param2 is deafult values for when a uri macthes the route pattern. So if a user types http://example/user/23, the router should map to user controller, profile action. The id, which is 23, will need to be injected into a request object. Finally the router object will be added to a front controller instance, so the front controller object can gain access to all the routes. Code: [Select] $router->mapRoute("user", new Route( "user/<id>", array( "controller"=>"user", "action"=>"profile" ) ) ); If any one has any ideas please do share, im not after code, unless you want to supply some, I just need some advice to stream line the whole process or what the best way might be. Any help will be greatly appreciated. Hey all, I'm using cakephp and it asks me a question and I'm not sure what to put in, because I don't necessarily know the consequences of what I put in: Code: [Select] Would you like to create the methods for admin routing? (y/n) [y] > y You need to enable Configu :write('Routing.admin','admin') in /app/config/core.php to use admin routing. What would you like the admin route to be? Example: www.example.com/admin/controller What would you like the admin route to be? [admin] > Thanks for response hi all,
this is my setup
Apache/2.2.15 (Unix)
PHP 5.4.36 (cli) (built: Dec 19 2014 06:28:27)
CentOS release 6.6
i am having intermmittent issues whenever in install pdo_oci and oci8 for PHP following this procedure
http://shiki.me/blog...ntos-6-4-64bit/
this is the full error
[root@localhost ~]# php -v PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/oci8.so' - /usr/lib64/php/modules/oci8.so: undefined symbol: php_checkuid in Unknown on line 0 PHP Warning: PHP Startup: PDO_OCI: Unable to initialize module location of oci8 [root@localhost ~]# cd /usr/lib64/php/ [root@localhost php]# ll total 8 drwxr-xr-x. 2 root root 4096 Jan 6 20:16 build drwxr-xr-x. 2 root root 4096 Jan 6 20:16 modules [root@localhost php]# cd modules/ [root@localhost modules]# ll total 4052 -rwxr-xr-x. 1 root root 69304 Dec 19 13:32 curl.so -rwxr-xr-x. 1 root root 2708336 Dec 19 13:32 fileinfo.so -rwxr-xr-x. 1 root root 46152 Dec 19 13:32 gmp.so -rwxr-xr-x. 1 root root 41576 Dec 19 13:32 json.so -rwxr-xr-x. 1 root root 49288 Dec 19 13:32 mssql.so -rwxr-xr-x. 1 root root 482372 Jan 6 14:15 oci8.so<<<<<======== -rwxr-xr-x. 1 root root 20256 Dec 19 13:32 pdo_dblib.so -rwxr-xr-x. 1 root root 124216 Jan 6 13:32 pdo_oci.so -rwxr-xr-x. 1 root root 101784 Dec 19 13:32 pdo.so -rwxr-xr-x. 1 root root 25984 Dec 19 13:32 pdo_sqlite.so -rwxr-xr-x. 1 root root 265584 Dec 19 13:32 phar.so -rwxr-xr-x. 1 root root 45744 Dec 19 13:32 sqlite3.so -rwxr-xr-x. 1 root root 41008 Dec 19 13:32 sybase_ct.so -rwxr-xr-x. 1 root root 94808 Dec 19 13:32 zip.so [root@localhost modules]# [root@localhost modules]# cd /etc/php.d [root@localhost php.d]# ll total 56 -rw-r--r--. 1 root root 49 Dec 19 13:32 curl.ini -rw-r--r--. 1 root root 57 Dec 19 13:32 fileinfo.ini -rw-r--r--. 1 root root 47 Dec 19 13:32 gmp.ini -rw-r--r--. 1 root root 49 Dec 19 13:32 json.ini -rw-r--r--. 1 root root 51 Dec 19 13:32 mssql.ini -rw-r--r--. 1 root root 18 Jan 6 14:16 oci8.ini -rw-r--r--. 1 root root 59 Dec 19 13:32 pdo_dblib.ini -rw-r--r--. 1 root root 47 Dec 19 13:32 pdo.ini -rw-r--r--. 1 root root 22 Jan 6 13:59 pdo_oci.ini -rw-r--r--. 1 root root 61 Dec 19 13:32 pdo_sqlite.ini -rw-r--r--. 1 root root 49 Dec 19 13:32 phar.ini -rw-r--r--. 1 root root 55 Dec 19 13:32 sqlite3.ini -rw-r--r--. 1 root root 59 Dec 19 13:32 sybase_ct.ini -rw-r--r--. 1 root root 47 Dec 19 13:32 zip.ini [root@localhost php.d]# more oci8.ini extension=oci8.so but if i do this [root@localhost php.d]# rm -fr oci8.ini [root@localhost php.d]# ll total 52 -rw-r--r--. 1 root root 49 Dec 19 13:32 curl.ini -rw-r--r--. 1 root root 57 Dec 19 13:32 fileinfo.ini -rw-r--r--. 1 root root 47 Dec 19 13:32 gmp.ini -rw-r--r--. 1 root root 49 Dec 19 13:32 json.ini -rw-r--r--. 1 root root 51 Dec 19 13:32 mssql.ini -rw-r--r--. 1 root root 59 Dec 19 13:32 pdo_dblib.ini -rw-r--r--. 1 root root 47 Dec 19 13:32 pdo.ini -rw-r--r--. 1 root root 22 Jan 6 13:59 pdo_oci.ini -rw-r--r--. 1 root root 61 Dec 19 13:32 pdo_sqlite.ini -rw-r--r--. 1 root root 49 Dec 19 13:32 phar.ini -rw-r--r--. 1 root root 55 Dec 19 13:32 sqlite3.ini -rw-r--r--. 1 root root 59 Dec 19 13:32 sybase_ct.ini -rw-r--r--. 1 root root 47 Dec 19 13:32 zip.ini [root@localhost php.d]# php -v PHP Warning: PHP Startup: PDO_OCI: Unable to initialize module Module compiled with module API=20090626 PHP compiled with module API=20100525 These options need to match in Unknown on line 0 PHP 5.4.36 (cli) (built: Dec 19 2014 06:28:27) Copyright © 1997-2014 The PHP Group Zend Engine v2.4.0, Copyright © 1998-2014 Zend Technologies no errror on PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/oci8.so' - /usr/lib64/php/modules/oci8.so: undefined symbol: php_checkuid in Unknown on line 0 [root@localhost php.d]# thanks in advance Edited by taliez, 06 January 2015 - 11:40 PM. In a project that I'm working on I can specify routing rules, which is somewhat similar to mod_rewrite but in PHP. It's currently set up to use full regular expressions, but it's kind of overkill. I'm trying to convert it to use routing rules similar to some of the php frameworks I've seen. The code I've written up below is working, and while it's unlikely that I would need anything more complex, I'm wondering if anyone would like to comment, offer suggestions, or offer criticisms. This little piece of code is just a part of a bigger routing class, but this is the code that I'm concerned with. Thanks.
<?php $cfg['routes'] = [ 'cars/(:any)/(:any)/(:num).php' => 'cars/$3/$1/$2', 'default_route' => 'cars/index', 'trucks/parts?year=(:num)' => 'parts/trucks/$1', 'vans/articles(:any)' => 'articles$1' ]; $uris = [ 'cars/toyota/tercel/2014.php', # /cars/2014/toyota/tercel 'default_route', # /cars/index 'trucks/parts?year=2014', # /parts/trucks/2014 'vans/articles?p=42342' # /articles?p=42342 ]; $i = 0; foreach( $cfg['routes'] as $k => $v ) { $k = '|^' . preg_quote( $k ) . '$|uiD'; $k = str_replace( [ '\(\:any\)', '\(\:alnum\)', '\(\:num\)', '\(\:alpha\)', '\(\:segment\)' ], [ '(.+)', '([[:alnum:]]+)', '([[:digit:]]+)', '([[:alpha:]]+)', '([^/]*)' ], $k ); echo '<br />' . $uris[$i] . '<br />' . $k . '<br />'; if( @preg_match( $k, $uris[$i] ) ) { echo preg_replace( $k, $v, $uris[$i] ) . '<br /><br />'; } $i++; } Routing issue: Cannot see a wireless router from a wired router on the same network. I have a very simple home network with a broadband connection from my ISP coming into the house with their 4-port modem/router (192.168.1.1) on it. From there I have 2 ethernet connections, one each to a wired router(192.168.1.7) and a wireless router(192.168.1.2) The wired router has one connection to my Debian Squeeze PC (usually 192.168.1.24) the wireless router has 2 or 3 connections to a PC and a tablet (usually something like 192.168.1.100 & 101... etc) The internet from my PC (192.168.1.24) is working fine through the wiired router, and the PC & tablet on the wireless router are working fine too. My problem is that I want to be able to 'see' the wireless router from my PC and I cannot connect to it or 'see' any of the connected devices. Maybe I am misunderstanding how this networking thing should work, but I think it should be possible to do this. Can anyone help me please? a) I have turned off iptables # iptables -F # iptables -L Chain INPUT (policy ACCEPT) target prot opt source destination Chain FORWARD (policy DROP) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination Chain logdrop (0 references) target prot opt source destination b) ifconfig -a eth1 Link encap:Ethernet HWaddr fc:75:16:e1:b8:13 inet addr:192.168.1.24 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::fe75:16ff:fee1:b813/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:9123 errors:0 dropped:0 overruns:0 frame:0 TX packets:9696 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:1100294 (1.0 MiB) TX bytes:844749 (824.9 KiB) Interrupt:20 Base address:0xde00 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:2740 errors:0 dropped:0 overruns:0 frame:0 TX packets:2740 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:247076 (241.2 KiB) TX bytes:247076 (241.2 KiB) b) I have added routes(I think) to the other router from my PC # route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.1.1 192.168.1.7 255.255.255.255 UGH 0 0 0 eth1 192.168.1.2 192.168.1.1 255.255.255.255 UGH 0 0 0 eth1 192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1 0.0.0.0 192.168.1.7 0.0.0.0 UG 0 0 0 eth1 # arp -an ? (192.168.1.7) at 00:14:6c:0b:1d:da [ether] on eth1 ========================================== from the other end, the wireless router when I connect a wired connection to a laptop I get the following similar picture (the broadband router) # ping 192.168.1.1 PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data. From 192.168.1.107 icmp_seq=2 Destination Host Unreachable From 192.168.1.107 icmp_seq=3 Destination Host Unreachable From 192.168.1.107 icmp_seq=4 Destination Host Unreachable ^C --- 192.168.1.1 ping statistics --- 6 packets transmitted, 0 received, +3 errors, 100% packet loss, time 5009ms pipe 3 (the wireless router) # ping 192.168.1.2 PING 192.168.1.2 (192.168.1.2) 56(84) bytes of data. 64 bytes from 192.168.1.2: icmp_req=1 ttl=64 time=0.378 ms 64 bytes from 192.168.1.2: icmp_req=2 ttl=64 time=0.381 ms 64 bytes from 192.168.1.2: icmp_req=3 ttl=64 time=0.452 ms ^C --- 192.168.1.2 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 1998ms rtt min/avg/max/mdev = 0.378/0.403/0.452/0.041 ms # arp -an ? (192.168.1.1) at <incomplete> on eth0 ? (192.168.1.2) at b0:48:7a:67:ea:7a [ether] on eth0 # route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 eth0 0.0.0.0 192.168.1.2 0.0.0.0 UG 0 0 0 eth0 # ifconfig eth0 Link encap:Ethernet HWaddr 00:16:d3:bb:64:09 inet addr:192.168.1.107 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::216:d3ff:febb:6409/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:5858 errors:0 dropped:0 overruns:0 frame:0 TX packets:5491 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:7093094 (6.7 MiB) TX bytes:666534 (650.9 KiB) Interrupt:17 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:121 errors:0 dropped:0 overruns:0 frame:0 TX packets:121 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:10032 (9.7 KiB) TX bytes:10032 (9.7 KiB) Edited by Zane, 28 December 2014 - 01:06 AM. This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=342468.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=345714.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=307000.0 |