Posts

php - Model from URL/API/JSON CakePHP -

i have new cakephp install , have series of web service endpoints in json, possible populate model json in cakephp? they won't connecting db data comes , submits web service. i have no code cannot find documentation on cakephp models site. rest datasource the storage mechanism model uses datasource. default cake assumes model used database can extends datasource class. there's an example in documentation of simple rest api datasource, , there many more datasources in the community datasources repository . it's not necessary build own rest datasource though, there existing solutions out there such this one make using model rest api rather trivial. examples readme: user::find('all') == http://api.example.com/users.json user::read(null, $id) == http://api.example.com/users/$id.json user::save() == post http://api.example.com/users.json user::save(array('id' => $id)) == put htt...

c++ - Can I use a member element as the default argument for a method of the class? -

the method minimum returns minimum element in binary search tree. if no argument passed prints minimum of calling object. if address of node passed prints minimum of subtree root node when compiled shows "invalid use of non static data member tree::root " #include<stdlib.h> #include<iostream> class node { public: node *leftchild; node *rightchild; node *parent; int info; }; class tree { public: node *root; tree() { root=null; } void minimum(node*); }; void tree::minimum(node *curnode=root) { node *parent; while(curnode!=null) { parent=curnode; curnode=curnode->leftchild; } std::cout<<parent->info<<endl; } int main() { tree tree; tree.minimum(); return 0; } no, cannot. for default value can use either value, variable or function accessible in context of function definition is, in class definition, outside of particular object's c...

php - CakePHP 1.3 - create() not setting created datetime? -

i'm upgrading system cakephp 1.1 1.3. when using create() (followed save()) in 1.1 system happily add insert entry database created , modified datetime fields set of time created. however, in 1.3 no longer correctly happening. here modified still set current time upon creation , save, created datetime not being set. suggestions why might occurring? thanks! create table code (as requested in comment): create table `units` ( `id` int(10) unsigned not null auto_increment, `id_b36` varchar(4) null default null, `subject_id` int(10) unsigned not null, `gradelevel_id` int(10) unsigned not null, `user_id` int(10) unsigned not null, `school_id` int(10) null default null, `district_id` int(10) null default null, `description` varchar(255) not null, `sort` float(5,1) not null default '0.0', `created` datetime not null default '0000-00-00 00:00:00', `modified` datetime not null default '0000-00-00 00:00:00', prima...

Conditional cumulative sum with apply functions in R -

may question addressed , answered in so, couldn't able find out. i'm computing cumulative sum conditions on large data frame. @ below example data=data.frame("catg"=c("a","a","a","a","a","b","b","b","c","c","c","d","d","d","d","d","d","d","d","e","e","f"),"val"=c(67,42,12,32,28,1,11,9,38,61,75,99,22,44,89,99,51,34,82,99,74,42)) res=null uniqcatg=unique(data$catg) for(i in 1:length(uniqcatg)) res=c(res, cumsum(data[data$catg==uniqcatg[i],"val"])) data$res=res data is there smart way without loops? (like apply functions) or plyr::ddply ... require( plyr ) ddply( data , "catg" , transform , res = cumsum(val) ) # catg val res #1 67 67 #2 42 109 #3 12 121 #4 32 153 #5 28 181 #6...

jQuery - How do I make sure a user enters text before performing any other operations? -

i'm allowing users create folders in app. once user clicks on "new folder" icon, display folder text box user enter name of folder. how make sure user enters name before clicking on "new folder" icon again or matter before using application else? i tried input change event, offcourse, fires when user attempts enter name. $(".new-folder-name").change(function () { var newfoldername = $(".new-folder-name").val(); if (newfoldername == "") { alert("please enter name new folder."); } else { alert("good, entered name: " + newfoldername); } }); but if user leaves text box blank , goes on doing other things app? how can force user enter text first before doing else? force user input after: alert("please enter name new folder."); add: settimeout(function() {$(".new-folder-name").focus();},10); forces focus on textbox. also, change .cha...

jquery - Is there a way to provide a fallback (local) image when the preferred (external/server/remote/cloud) image fails to load? -

i have anchor tags so: <a href=\"http://www.duckbill.com" target=\"_blank\"><img height=\"160\" width=\"160\" src=\"http://images.duckbill.com/platypionvacation.jpg\" alt=\"platypi playing pinochle , eating pizza in panama\" /></a> ...that fail load src image; in such cases i'd to, after sufficient delay (a couple of seconds), replace with: <a href=\"http://www.duckbill.com" target=\"_blank\"><img height=\"160\" width=\"160\" src=\"content/images/platypionvacation.jpg\" alt=\"platypi playing pinochle , eating pizza in panama\" /></a> i know in jquery, how able programmatically determine remote file did not load and, when such case, respond using fallback image? update i brad christie's answer unavailable images, want never show "unavailable" - use local 1 if remote 1 not available @ moment. this: h...

php - Simple HTML DOM - traversing html -

i'm using simple html dom parser - http://simplehtmldom.sourceforge.net/manual.htm i'm trying scrape data scoreboard page. below example shows me pulling html of " akron rushing " table. inside $tr->find('td', 0) , first column, there hyperlink. how can extract hyperlink? using $tr->find('td', 0')->find('a') not seem work. also: can write conditions each table (passing, rushing, receiving, etc), there more efficient way this? i'm open ideas on one. include('simple_html_dom.php'); $html = file_get_html('http://espn.go.com/ncf/boxscore?gameid=322432006'); $teama['rushing'] = $html->find('table.mod-data',5); foreach ($teama $type=>$data) { switch ($type) { # rushing table case "rushing": foreach ($data->find('tr') $tr) { echo $tr->find('td', 0); // first td column (player name) echo $tr->find('td...