Jump to content

Rob

Members
  • Posts

    134
  • Joined

  • Last visited

Everything posted by Rob

  1. I've used twig templates, it's pretty easy once you have the twig bits set up to just call twig to spit out templates from the normal processwire PHP pages. I have recently started a project where I use PW purely as a CMS tool, and then have a totally seperate site (sat side by side on the same server) that uses the PW API to pull data and inject into twig templates. I have used the Silex PHP microframework, but the API is so good you could use it from any PHP code you like. If you want to use PW as a CMS and page-modelling tool and then any other set of code to actually spit out a site to the end user, it's no problem. I'm not a fan of HTML+PHP templates, and a template language like twig is much more powerful and flexible in many ways. Inheritance of templates, sandboxed template tags, ability to create custom tags, caching, very intelligent iteration and filtering/processing to do all kinds of stuff. Not a necessity by any means (and not an insult to PW), just shows that there are many options available that can utilise the real unique power of PW (the page/data modelling and the query API) and then whatever tool you feel comfortable with to build the site. By using Silex, we have very fine control over our site structure. The site URL structure need not mimic how the pages (or generic pieces of data as we see it) are held in the PW page tree. We are basically using PW as a data/page repository (like a big XML document full of data), then using that data in whatever way we like with the API. If you see PW as a data-modelling tool, rather than a page-modelling tool, it opens up a whole new way of thinking about things. Each "page" in PW is really just a unit of data, it need not actually represent a page if you don't want it to. This was typed in a rush as I head out the door, so I hope it makes sense and gives some food for thought!
  2. Rob

    DataTable

    Hi again Soma. Did you ever experience any problems with caching? I have a strange issue where my getdata() method returns new data if I use the pagination links but does not if I use the headers to change the sort column or direction. I thought it might be client-side cache but it seems unlikely if it works with some requests and not others. I have compared the request vars going to the server with your datatable code and I haven't spotted any extra fields or otherwise different behaviour. The AJAX request is definitely being made and the request params are changing with the different heading clicks, but the returned data doesn't change unless I use the pagination links.
  3. Rob

    DataTable

    Somehow I'd ended up with this line... $this->config->js($this->className(), $lang); ...BEFORE I'd set up the $lang array. I moved it after and it's rendering the table now. Next up....set up the AJAX handler method to work properly. Thanks for trying to help!
  4. Rob

    DataTable

    Yep your module works fine as far as I can tell.
  5. Rob

    DataTable

    It's in the admin. I'm now diffing my files with yours again to see the differences and work out if there's something vital going on that I've missed.
  6. Rob

    DataTable

    Thanks Soma. I suspected that the init script was being run by the core DataTable code but I didn't check to be honest. I haven't changed the table class or anything else really. I have changed module-related data such as name but I haven't fiddled the JS code. I've even run diffs on my code vs yours to try to find anything glaring but nothing jumps out at me. Very strange!
  7. Rob

    DataTable

    I'm trying to use this module as a starting point for my own DataTable-based module, but I'm running into a few problems. I've basically copied the entire code into a new folder so I can rename the class, JS file etc try to return some static JSON in my new executeGetData() method, but when my new page first loads the function is never being called. That is to say that the AJAX request isn't being made. I'm no JS expert so I can't work out if there's some place where the initial request is being made from within the JS code in DataTable.js. Ultimately my question is this: - When I first load the DataTable page, from where does the very first AJAX request get called that turns the plain HTML table into the DataTable? I have the duplicated JS and CSS classes in the same folders underneath my module folder and I have checked (with Firebug) that all files are being loaded correctly, so I'm now at a brick wall!! Thanks in advance.
  8. It was permissions I think. I was trying to fetch repeater data but these are superuser-only pages hidden under /admin so it didn't work from my php interactive mode code.
  9. I've been trying to get a bunch of pages based on id, and according to the selector documentation the following should work: wire('pages')->find('id=6|7|8|9') But it doesn't seem to as I get an empty set returned. Each of those page IDs is valid and if I do the following: wire('pages')->find('id=6'); I get a PageArray with one item. Can anyone tell me if I'm doing something wrong?
  10. Hi all. I've been using PW for a few months now and I'm very much enjoying it on the whole. Before the repeater field became available I had, with the help of Ryan, coded my own repeater-style field that uses JS etc so I could have a multi-part field (in this case a URL and text for a link) and was able to add/delete as many of these items to a page as I like. The issue here was really the learning curve in understanding the underlying code and making it work correctly with the load/save of data and the JS interface bits. Not super complex, but not easy either! Now the repeater has come along it means it is possible for us all to make much more complex data models, which can only be a good thing, without needing the ability to develop our own code. The benefit of the repeater field comes at one price that I have noticed, and that is that the DB structure suffers in terms of readability. When I wrote my own code it saved all the data into a single DB table like "regular" fields and so when, as a developer, I needed to go into the DB manually to check things or do debugging it was straightforward. I can easily see what data is attached to what page. With the repeater, there is a layer of abstraction added. It makes it more difficult to analyse the page data and also, I suspect, it adds a bit of DB performance overhead although it is likely so small as to be insignificant in most typical CMS cases i.e. not millions of page impressions. I just wanted to kick-start an open discussion about the benefits of either approach and if there are any pitfalls we should be aware of or practises that we should try to stick to. I think the repeater is a brilliant concept and it opens up PW to a whole world of more complex uses as a data modelling tool, but I think perhaps we need to tread carefully and consider the bigger picture and whether it is suitable in all cases.
  11. Something I really can't get my head around is that it seems liks wakeupValue() isn't being called if there is no value for a field in the DB. The echo statement in the following code produces "Array" if there is any value in the DB and nothing at all happens (so it must be being skipped) if there is no value. This implies to me that a regular array, not a WireArray, is what is being returned. This is also supported by the fact that when I call $value->getArray() as suggested, I get an error about calling a method on a non-object. public function ___wakeupValue(Page $page, Field $field, $value) { echo $value; exit; return implode(', ', $value->getArray()); } Ryan - I'll email you the whole module code and perhaps you can shed some light on the issue. In the past I posted on the subject of the relationship between wakeupValue(), sleepValue() and sanitizeValue() and I'm still not clear!!
  12. I'm trying to write a FIeldtype that stores tags. The basic idea is that it uses a standard Text Inputfield and takes the string entered, separates the values by comma and then saves each one as a tag. WHen it loads the values I preferably want the values to remain as an array of item in the page data, but be displayed as a simple comma-seperated lsit inthe InputField. I'm extending a FieldTypeMulti but I see mto be running into some sort of problem when there is no value associated with the filed in the DB, as it displays "WireArray(0)" in the InputField. I was originally taking the WireArray being returned from the DB and concatenating (using PHP implode() method) back into a string so the InputFIeld can display it. I've gone round in circles and I can't work out exactly what I have t odo to successfully either: A. Keep the data as an array from the DB, but successfully display it as a string in the InputFIeld. OR B. Convert the array from the DB into a simple string, and I can then re-explode it into individual tags if I want to iterate them in my template. An extract of my FieldTypeTags code looks like this at present, although I've tried about 5 different things before this!! public function ___sleepValue(Page $page, Field $field, $value) { $data = array(); foreach(explode(',', $value) as $tag) { $data[] = array('data' => trim($tag)); } $clean = array_filter($data, function($item) { return !empty($item['data']); }); return $clean; } public function ___wakeupValue(Page $page, Field $field, $value) { return implode(', ', $value); } public function sanitizeValue(Page $page, Field $field, $value) { return $value; } I'm going absolutely mad with this. I can successfully store the tags in the DB as separate values, whcih is great for searching and doing tag cloud counts etc, but I can't get the InputField to behave properly when there is nothing stored for the field.
  13. Hi Adam. I think the code is on github somewhere and I could probably find it, but it's so specific to the CMS in question that it really wouldn't be relevant here. What we need to figure out is whether the hooks in question are available in the core and then tap into them to basically log every DB schema change. I know from previous talks with Ryan that basically any function in the core can be made hook-able, but that there are performance implications in many cases so it has to be carefully considered. That said, in this case it has nothing to do with page dispatch/render and is purely linked to back-end activity so it shouldn't affect site performance. I'm sure he'll chime into this discussion when he gets the chance!
  14. It occurs to me that a module that records all alterations to DB schema would be useful for the migration of DBs from a staging/development environment to live or vice-versa. I was thinking that, at present, if I work on my site locally (LAMP stack on my laptop etc) and then need to push changes live that it is no problem from a code point of view (I use git for source control, comfortable with that process) but that DB schema changes may be a bit more of a pain. I can, of course, just recreate the fields and templates manually on the live site but it's not exactly convenient or intuitive!! I have not checked, but if there are hooks into the DB parts of the core that make changes to the schema for new fields, template structure etc then it shouldn't be too hard to record those changes into a log that will therefore be a series of SQL commands that can be run to update the DB schema on another installation. I'm slightly lacking the time to do this myself, but I suspect that there are talented module devs here who could do this in no time, assuming the hooks are in place. An ex-colleague wrote a plugin for another CMS which did the same thing and it was very helpful indeed.
  15. Finally got round to trying this, works a treat. I've never quite mastered the black art of Apache Rewrite so you've done me a big favour. Thanks!
  16. We want to stick our whole site behind HTTPS and only let through requests for /processwire/* pages so that the site acts purely as a CMS, and then we're developing our own front-end page dispatch code using the API. I've been going mad trying to work out how I need to modify the htaccess file (or indeed the underlying virtual host in apache) so that I can whitelist only /processwire/ pages. I want anything that starts with /processwire to get through and any other page requests (other than those for resources such as assets, css, javascript etc) to to be forbidden. In theory it should be simple but I have tried all manner of things and nothing works. Can anyone with a better knowledge of apache help me out?
  17. It's always an interesting debate regarding the relative merits of PHP. I think it's probably the easiest language to pick up and get developing with for the web, but it's hard to argue against some of the criticisms from other more "pure" OO languages like Python or Ruby. I think PHP is flawed and it has the unfortunate legacy of a procedural language that has had OO bolted on. For that reason I'm always glad of frameworks and CMS' that have great design and best practise behind them, like Symfony2, because it makes me a better developer by standing on the shoulders of others! But I think I agree with you that there's no need to abstract everything, especially when it's something simple. If I'm totally honest, when I look at Python I'm jealous of how clean and terse the syntax is. But It'd take me a long time to transfer all my PHP knowledge across and get up to speed! I digress...
  18. I've just realised a potential problem. When I was first looking at this repeatable field stuff, I did a workaround to the hard-coded one-dimensional array limit that was in the code. When I upgraded to 2.2 I probably overwrote that so now the WireInputData class isn't even returning the data from the field. I can easily just us _POST but it seems like a kludge when there is a sanitising input class in the PW core. I didn't ever submit a pull request as I thought it'd be best to leave you (Ryan) to make the change yourself. You said at the time that if I needed multi-dimensional array support, others probably would too. http://processwire.c...nal-arrays-why/ Is this still on the agenda?
  19. Thanks for the pointer Ryan. My pages save fine, probably because I'm returning the data from the InputField with the data converted back to the right key/value pairs in the array. I suppose in the case of a page save when the data to be saved has been set from the recently submitted InputField then it doesn't matter (because of the above point), but when the page clone takes place PW has loaded the data which alters the array keys, then gets confused when it tries to save into columns that don't exist.
  20. As requested Ryan, the code to my FieldType. I wonder now if it's got anything to do wit hthe fact that IO am converting the data slightly (change array key) on wakeupValue() before it gets handed to the InputField, but if the two are totally separate and they only pass data back and forth, this shouldn't have anything to do with the clone. The clone is a purely data-related operation, so should have nothing to do with display or input, correct? class FieldtypeLinkMulti extends FieldtypeMulti { public static function getModuleInfo() { return array( 'title' => 'Multiple Link Field', 'version' => 001, 'summary' => 'Field that stores multiple links with URL and link text' ); } public function getDatabaseSchema(Field $field) { $schema = parent::getDatabaseSchema($field); $schema['data'] = "varchar(255) NOT NULL"; $schema['text'] = "varchar(255) NOT NULL"; return $schema; } public function getInputfield(Page $page, Field $field) { $inputfield = $this->fuel('modules')->get('InputfieldLinkMulti'); if(!$inputfield) return null; return $inputfield; } public function ___sleepValue(Page $page, Field $field, $value) { return $value; } public function ___wakeupValue(Page $page, Field $field, $value) { $links = array(); foreach($value as $link) { $links[] = array( 'url' => $link['data'], 'text' => $link['text'] ); } return $links; } public function sanitizeValue(Page $page, Field $field, $value) { return $value; } }
  21. I've upgraded to 2.2 to see what's new and one of the useful things for us is page cloning. Unfortunately there seems to be a problem when I try to clone a page that has fields that are of a custom type I have created myself. When I try to clone the page I get the following message "Unknown column 'url' in 'field list'" and having turned on debugging I can see that the code is trying to create a new DB record with a 'url' column which doesn't exist. My custom field uses the standard 'data' column for storing the URL and it loads and saves fine ordinarily. Can anyone suggest if there is some extra method that I need to implement in my custom FieldType so that the clone functionality knows exactly how to clone the data? It is worth mentioning that this is a custom FieldType and InputField that has multiple parts and is repeatable. Basically a field that holds a piece of text and a URL to represent a link, and you can add multiple sets of these links. Thanks is advance. p.s. upcoming repeating fields functionality looks very exciting, and very powerful., based on the video Ryan posted.
  22. Thanks for the code exampel Ryan, that's basically the kind of thing I was already doing, I was just hoping there would be a simple way to do it with API, selectors etc. Seems like a lot of DB load to fetch all that stuff just to get a small part of it. What I've actually done is just so a direct DB fetch for everything from the tags table, as I was using a custom Fieldtype. I don't actually mind using direct DB access where it makes sense, although I was a bit confused by your DatabaseQuery and DatabaseQuerySelect classes (I think they were called) as I couldn't work out how to use them and how to add criteria then make a DB query call. Not to worry!
  23. I've created a page that is basically used as a big image repository. The page has a single field with multiple items. Each item is an image field with extra parts to add tags. So what I want to do is pull a list of every image from that field in that page (no problem) but then pull every unique value from the "tags" part of the field within each image. So if I wanted to create a tag cloud based on the values within a certain field, how might I do that? To clarify - I can grab a single page and then every image in a multi-item field, but what I then need is the value from the 'tags' part of each of those images.
  24. I'm having a play with bootstrapping and using alternate tools for request/response and templating. I'm a huge fan of the Symfony2 framework and it's constituent components. If you haven't had a look I'd recommend it, the developers seem to have a very strong grasp on clean, modern, best-practise architecture. In terms of PHP frameworks and code quality I think it's the best I've ever seen, Fabien Potencier seems to be very forward-thinking. My ultimate aim is to have an "admin.mysite.com" domain for the back-end and then write my own dispatcher that will live at "mysite.com". At this stage it seems entirely plausible, but I can't work out how to make the admin subdomain/site ONLY deal with CMS-realted page requests. In fact it'd be great to be able to filter out the "front" page requests and also get rid of any "/processwire" part of the URL for CMS requests so it looks cleaner. All the above are non-essential though, it's more my own curiosity than anything!
  25. I think I may have got the tone of that last post a bit wrong, I didn't mean to sound negative in any way. It appears that "spitting out content" is how the tutorials presented the CMS as working, but as you say there is no necessity to do that. I suppose what I'd really like to do (and what I've often wanted to do with CMS' I've used) is to essentially leave the back-end intact to manage the data in/out and build my own dispatcher because that way I can get as creative as I like and maintain a lot of control. I think perhaps if I dig into the API a bit more deeply I may be able to essentially separate the whole thing in two. I can perhaps run the CMS as a subdomain and then have the principle domain for my own dispatcher, pull the page data etc myself and do with it as I please. Judging by the brief exposure I've had to the API, it appears to be very well-built and geared towards flexibility and modular design so I think it's a good candidate for this sort of thing.
×
×
  • Create New...