Jump to content


New Members
  • Content Count

  • Joined

  • Last visited

Community Reputation

0 Neutral

About JayNic

  • Rank
  1. Thanks for your help - I ended up getting it working with the following: <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /api RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule (.*)$ index.php?request=$1 [QSA,NC,L] </IfModule> and in my /api/index.php file I can see everything: //api/index.php if (!array_key_exists('HTTP_ORIGIN', $_SERVER)) { $_SERVER['HTTP_ORIGIN'] = $_SERVER['SERVER_NAME']; } $echo = [ "request" => $_REQUEST['request'], //The request directory with get params "getParams" => isset($_GET) ? $_GET : null, "postParams" => isset($_POST) ? $_POST : null, "fileInput" => file_get_contents('php://input'), "httpOrigin" => $_SERVER['HTTP_ORIGIN'] ]; echo json_encode($echo)
  2. Thanks for the reply - I think I'm still not getting it right... cause now I still get the "index of /api" screen. I have the following structure: the and files: .htaccess <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /api RewriteRule ^api\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /api.php [L] </IfModule> api.php <?php header("Content-Type: application/json; charset=utf-8"); echo json_encode(["hey"=>"there"]); but I'm still getting this:
  3. Hi all, I really don't understand htaccess very well, and I feel like what I'm trying to do is simple, but I can't get it to work. I have a wordpress site, and in the public_html folder is the .htaccess file with the following body: # Use PHP54 Single php.ini as default #AddHandler application/x-httpd-php54s .php # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress That's all fine for the public website, but I'm trying to build a rest api in a subdirectory: www.example.com/api/ - and I want all requests that go anywhere in /api to go to my single file: www.example.com/api/myapp.php then I plan on just handling everything with some php in there by parsing the path: $path = strtolower(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)); $path = rtrim($path, '/'); //remove trailing slash // ... do stuff based on path So for example, if I made a POST request to: https://www.example.com/api/v1/dothing - then myapp.php would find that $path is "/api/v1/dothing" Then I can grab post params, get params what have you... I don't want to impact the current wordpress site - ONLY the /api directory... Thanks for your help
  4. Hi guys, I have some questions regarding how best to generate guaranteed non-repeating base36 ids for my records. I have many years experience in Salesforce APEX coding. As such, I'm extremely comfortable working with their id system. I'd like to accomplish something similar in my personal WAMP framework. Here is a sample id of what I'd like to get. $myId = 'A0B00000000341K'; Some basic rules: * The ids should always be 15 characters long. * The Ids must be immutable * The ids should never repeat. Even if I attempt to execute dml on records, and this results in an exception in my application - I will use transaction control to rollback the dml. Any ids generated and subsequently rolled back should never be used again. * The first three characters of an id should represent the table where they belong. This way - I can determine what I am looking at based on whatever id I pass in. I can also validate foreign relationships on table by confirming the id being looked up to is of the appropriate type So in the above example: I have an id belonging to a table with an id of A0B. What I need guidance on -- where the different parts of the business logic should live. I have created a simple trigger system in mysql as a prototype. It looks as follows: Table structure I have a configuration table that stores some of the needed info. Table: 'jObject' Field: 'id' - The id of the jObject. In our above example - this would be 'A0B' Field: 'name' - The Name of table with that id. for example: 'myTableName' Field: 'totalInserts' - The total attempted inserted records in the table. RecordIdGenerate A mysql function to generate an id based on the table name you pass in. It finds a field called 'totalInserts' in another table - and updates it. BEGIN DECLARE jObjectCount BIGINT(20); DECLARE jObjectId CHAR(3); SELECT id, totalInserts INTO jObjectId, jObjectCount FROM jObject WHERE name = pObjectName; RETURN CONCAT( jObjectId, LPAD( CONV(jObjectCount,10,36), 12, '0000000' ) ); END Triggers on my tables (example table name: myTableName) SetRecordId: A before insert trigger that calls the function to get the id BEGIN SET NEW.id = RecordIdGenerate('myTableName'); END UpdateTotalInserts: An after insert trigger to update my jObject table with the total number of inserts it's undergone: BEGIN UPDATE jObject SET totalInserts = totalInserts + 1 WHERE name = 'myTableName'; END What I don't like about this solution 1) It's not batchable. There are updates, and selects being done for every row inserted. This seems really inefficient, and bad practice. 2) I'm using base 36 ids to get away from the number of characters needed in base 10 ids, but I have to store a base 10 id in the jObject table to generate the base 36 id anyway... This seems wrong to me. 3) I don't know what happens if I rollback a transaction. Will the value placed in 'totalInserts' on jObject rollback too? My business rules say it should not... 4) I don't know how I can sort these ids... Do I need some special sorting function? Will it sort alphabetically - Ideally it shoudl sort by them numerically... So basically. I guess I want to know if all this logic should be pushed to my php layer, and not the mysql layer. I feel like it should, but I want to know how best to meet my business requirements I mentioned above. I really appreciate any insight. Thanks JayNic

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.