Jump to content

clsource

Members
  • Posts

    374
  • Joined

  • Last visited

  • Days Won

    8

Everything posted by clsource

  1. Thats something I wasnt aware of. It will shrink the fields counter a lot, beause I was using them the way you said described. A field for each template so they had different input messages and labels. Thanks
  2. I said namespacing fields to refeer having 2 fields with the same name but different input/output formatting. I think this could be a corner use case. But can reduce the need for prefixes and if you use tags (categories), probably it will increase user experience.
  3. Yes I know that is possible . But I find using prefixes for field naming a bit awkward. I usually work with many fields, and since PW currently does not have a field selector that can sort by categories I have to rely on prefixes, so I can use the right field for the template.
  4. I think I found a temporary solution. I wish there was someway to sort field selection in templates using categories. The solution is the following create a models directory in /templates/ prefix fields as normal For example an user usrFirstName a model named /models/User.php that wraps all the user related data <?php class User { public $firstname; public $page; public function __construct($user) { // fill the vars $this->firstname = $user->usrFirstName; $this->page = $user; } // finds a specific user and creates a new User Object public static function get($id) { $userPage = wire('pages')->get("/users/$id"); $user = NullPage; if(!($userPage instanceOf NullPage)) $user = new User($userPage); return $user; } } Now you can have pretty property names like $user = User::get('clsource'); echo $user->firstname;
  5. Yes, The verb is on the Http Request and different responses are given depending on the way you call an endpoint. If you got www.your-pw-site.com/products/ then you can have these methods GET -> list of products POST -> create a new product then if you got this particular product "computer-1" www.your-pw-site.com/products/computer-1 you can have these methods GET-> info of computer 1 PUT -> replace all the info of computer 1 PATCH -> replace specific info like name or sku of computer 1 DELETE -> removes computer 1 Now taking that as an example, you can have this way to program and endpoint in Processwire 1.- Create a template named "products" (with a file products.php in templates folder) 2.- Create a page that use that template, and creates the url www.your-pw-site.com/products/ (Enable UrlSegments) 3.- Now products.php will be coded like this Note that Product.php is just a helper class that just have some methods for easier output formatting <?php require_once './includes/Rest.php'; require_once './models/Product.php'; // Vars with the default output $code = 200; $output = null; $header = Rest\Header::mimeType('json'); // First check if you have Url segment1 // this segment you can have the product id if($input->urlSegment1) { $productId = $input->urlSegment1; $product = Product::find($productId); // Check if we found a product if(!($product instanceOf NullPage)) { // Convert the page object to our model $product = new Product($product); // Detects the Verb if(Rest\Request::is('get')) { // json encodeable array $output = $product->get(); } else (Rest\Request::is('put')) { $params = Rest\Request::params(); $output = $product->put($params); // Could be 202 if modification is made async // 200 if OK // $code = 202; } else (Rest\Request::is('patch')) { $params = Rest\Request::params(); $sku = $params['sku']; $output = $product->patch('sku', $sku); // Could be 202 if modification is made async // 200 if OK // $code = 202; } else (Rest\Request::is('delete')) { $output = $product->delete(); } // Product not found } else { $code = 404; $output = Product::notFound(); } } else { // Detects the Verb if(Rest\Request::is('get')) { $params = Rest\Request::params(); $page = $params['page']; $output = Product::fetch($page); } else (Rest\Request::is('post')) { $params = Rest\Request::params(); // You can get the params like // $params['name'], // $params['sku'] // and so on $newProduct = Product::create($params); // Returns and array that can be json encoded $output = $newProduct->get(); // 201 Created $code = 201; } } // End if // Show the response and body http_response_code($code); header($header); echo json_encode($output);
  6. Hello, I always put some kind of prefix to fields like some user fields usrFirstName usrLastName but I would like to name them more like firstName lastName so when using a page like this $user = $pages->get('/users/clsource'); I can do this $user->firstName and not this (more ugly way) $user->usrFirstName Yes I know this is already possible, but when you handle a lot of fields, some fields collide with the same name but with different output and format. Is there a way to make a namespace or something, so using prefixes is no longer necessary? In PW you can organize fields inside categories, could be that I can have multiple fields with the same name, but whitin different categories. and see them sorted inside the template field selector by categories? Thanks!.
  7. clsource

    SkyNet is coming

    Praise the mutant saviour
  8. I have added additional links
  9. haha xddd well but that does not mean it is a bad choice for a certification authority. I think
  10. By the way an alternative to prestashop and opencart is tomatocart http://www.tomatocart.com/ but I don't have experience with that.
  11. yep ssl I think you can get one certificate free here http://www.cacert.org/
  12. Ok so this is the result of a more RESTful PW https://github.com/clsource/ProcessWire/tree/dev/wire please test it out if you have some spare time thanks
  13. Thanks man. By the way, I forked PW and added RESTful capabilities to the Core https://github.com/clsource/ProcessWire/tree/dev/wire
  14. thanks guys I'll let you know when the stuff is done
  15. Hello, since my post about RESTful Processwire https://processwire.com/talk/topic/7159-rest-helper-for-processwire/ was quite popular (thanks for showing it in the newsletter by the way ) I'm planning to include some of the helper code inside the PW core and then make a pull request in the hopes that merges with the current dev branch. So far I have identified 3 files that I should modify /wire/core/WireInput.php So I can add a "params" method in order you can have any params for any request method get post, put delete etc. /wire/core/WireHttp.php So I can add method to send put delete patch requests, etc. and get JSON output /wire/config.php So I can add more fieldContentTypes and Header types for the response. In the same file however, you got this /** * ajax: This is automatically set to TRUE when the request is an AJAX request. * */ $config->ajax = false; Where I can find the code to set this? So I can add $config->post = false; $config->get = false; $config->put = false; $config->delete = false; And set them when a page is requested when a verb is used to call an endpoint. Thanks!
  16. Yes I have the same Issue running the lastest dev branch. My vagrant box was running apache as www-data (Ubuntu trusty 32) so I changed to the current user (vagrant in my case) in this file sudo nano /etc/apache2/envvars changed these two lines from this export APACHE_RUN_USER=www-data export APACHE_RUN_GROUP=www-data to this export APACHE_RUN_USER=vagrant export APACHE_RUN_USER=vagrant then reloaded apache config with sudo service apache2 restart and I could log in
  17. Well basically when you follow the RESTful approach when creating systems, you use resources rather than actions. you can know more here http://restcookbook.com/ http://restpatterns.org/ http://www.restapitutorial.com/ and this books https://leanpub.com/build-apis-you-wont-hate http://www.soa-in-practice.com/ Example if you want to make an admin for the users resource. you can have this URL http://api.example.com/users In the traditional CRUD aproach, the verb is inside the URL like http://api.example.com/users/create but in REST you must use only HTTP Verbs to interact, so the same endpoint url makes different actions depending on the verb used to call it. In our system that could be http://api.example.com/users GET - result in a list of users POST - creates a new user ------------------------------------- http://api.example.com/users/clsource GET - result in the user data PUT - updates the all the data of a specific user PATCH - updates a specific data field of a specific user DELETE - deletes the user Using the HTTP response codes and mime types you can notify the result of an operation, usually with a JSON or XML body for information. The Web services Approach, specially REST web services, enables us to separate complex systems in smaller ones, easier to mantain and test. Basically you can have multiple backend systems that just are APIs and one frontend system that glue them all. this add a layer of security and robustness, because you can separate your systems in different servers. A possible attack can not affect all the system, just small parts of it.
  18. Hello, I created a simple REST helper in order to create REST APIs with Processwire, without depending on external routers Here you go!. https://gist.github.com/clsource/dc7be74afcbfc5fe752c
  19. i Think this could answer https://processwire.com/talk/topic/6849-getting-page-field-data-outside-pw/ my own question xdd thanks
  20. Hello, I´m trying to make a REST API with PW. is there something like $wire('input')->get and $wire('input')->post but for the verbs delete and put? also how can I separate the code for each verb. example: I have the following endpoint /users/emails Processwire can detect what verb is beign used to call that endpoint? (automatically call the corresponding code paired with the verb) or I have to manually check it and execute the corresponding code, using an if or something similar. basically I am looking for a router like Lime https://github.com/aheinze/Lime If PW does not have a router, using wire('pages') inside Lime it´s possible without conflicts? Thanks.
  21. wow, so I guess I have to wait until PW 3! well, I think that I should create a REST API then if I want that kind of functionality. Thanks!
  22. Hello, I have the following question. I want to separate a big system into smaller sub systems, each with a separate pw setup. The question is: how can I access the wire('pages') of another pw installation?. example: a big system that handles users and mail sending. the users system "A" is a pw setup in directory users/ the mail sending system "B" is another pw setup in directory mails/ both systems are in the same machine and directory. inside the "A" system I want to know how many emails an user have sent. so the "A" system request this information to the "B" system. It is possible to just import index.php from system "B" and access its wire('pages') variable? or the only way is using something like a REST API?. Thanks in advance.
  23. Really awesome module, great work! I just have one question, If in one controller I need to render two different templates how can it be done? Example home controller and two themes, one for night other for day. So the controller check the time and load the corresponding view.
  24. maybe this is helpful too http://mqtt.org/
×
×
  • Create New...