Search Results

Search found 36 results on 2 pages for 'spawncxy'.

Page 2/2 | < Previous Page | 1 2 

  • Problem with altering model attributes in controller

    - by SpawnCxy
    Hi all, Today I've got a problem when I tried using following code to alter the model attribute in the controller function userlist($trigger = 1) { if($trigger == 1) { $this->User->useTable = 'betausers'; //'betausers' is completely the same structure as table 'users' } $users = $this->User->find('all'); debug($users); } And the model file is class User extends AppModel { var $name = "User"; //var $useTable = 'betausers'; function beforeFind() //only for debug { debug($this->useTable); } } The debug message in the model showed the userTable attribute had been changed to betausers.And It was supposed to show all records in table betausers.However,I still got the data in the users,which quite confused me.And I hope someone can show me some directions to solve this problem. Regards

    Read the article

  • modify array in loop

    - by SpawnCxy
    Here is the code: $arraya = array('a','b','c'); foreach($arraya as $key=>$value) { if($value == 'b') { $arraya[] = 'd'; //print_r($arraya); //$arraya now becomes array('a','b','c','d') } echo $key.' is '.$value."\n"; } and it will get: 0 is a 1 is b 2 is c And I wonder why 3 is d doesn't show up??

    Read the article

  • where should I do the calculating stuff,PHP or Mysql?

    - by SpawnCxy
    I've been doing a lot of calculating stuff nowadays.Usually I prefer to do this job in PHP rather than Mysql though I know PHP is not good at this cuz I thought mysql may be worse.But I found some performance problem :some pages were loaded so slowly that 30 seconds' timelimit is not enough for them!So I wonder which is the better practice to do the calculations,and any princles for that?Suggestions would be appreciated.

    Read the article

  • detect a string contained by another discontinuously

    - by SpawnCxy
    Recently I'm working on bad content(such as advertise post) filter of a BBS.And I write a function to detect a string is in another string not continuously.Code as below: $str = 'helloguys'; $substr1 = 'hlu'; $substr2 = 'elf'; function detect($a,$b) //function that detect a in b { $c = ''; for($i=0;$i<=strlen($a);$i++) { for($j=0;$j<=strlen($b);$j++) { if($a[$i] == $b[$j]) { $b=substr($b,$j+1); $c .=$a[$i]; break; } } } if($c == $a) return true; else return false; } var_dump(detect($substr1,$str)); //true var_dump(detect($substr2,$str)); //false Since the filter works before the users do their posts so I think the efficiency here is important.And I wonder if there's any better solution? Thanks!

    Read the article

  • How should I use try...except while defining a function?

    - by SpawnCxy
    Hi all, I find I've been confused by the problem that when I needn't to use try..except.For last few days it was used in almost every function I defined which I think maybe a bad practice.For example: class mongodb(object): def getRecords(self,tname,conditions=''): try: col = eval("self.db.%s" %tname) recs = col.find(condition) return recs except Exception,e: #here make some error log with e.message What I thought is ,exceptions may be raised everywhere and I have to use try to get them. And my question is,is it a good practice to use it everywhere when defining functions?If not are there any principles for it?Help would be appreciated! Regards

    Read the article

  • What's the benefit of function refrence?

    - by SpawnCxy
    When I reading the code of CodeIgniter,I found some functions written as follows: function &get_instance() { global $CI, $OBJ; if (is_object($CI)) { return $CI; } return $OBJ->load; } I can understand variable refrence,but I can hardly get this through.Is it necessary to use this function style?And any benefit? Thanks.

    Read the article

  • how does array_diff work?

    - by SpawnCxy
    I just wonder how array_diff() works.And obviously it couldn't work as follows function array_diff($arraya, $arrayb) { $diffs = array(); foreach ($arraya as $keya => $valuea) { foreach ($arrayb as $valueb) { if ($valuea == $valueb) { break; } $diffs[$keya]=$valuea; } } return $diffs; } //couldn't be worse than this Hope someone can show me some better solution. Thanks.

    Read the article

< Previous Page | 1 2