phpactiverecord

PHP ActiveRecord: How do I add multiple conditions?

北战南征 提交于 2019-12-08 08:02:02
问题 I'm trying to bind more than one condition in php ActiveRecord How can I change the below code (which works) to bind another condition? $events = Event::find('all', array( 'conditions' => array('event_type = ?', array('opera')), 'select' => 'col1, col2, col3', )); Thanks! 回答1: Try this $events = Event::find('all', array( 'conditions' => array('event_type = ? AND event_hour = ?', 'opera', 'your_event_hour'), 'select' => 'col1, col2, col3', )); 回答2: $objectChanges = Table_model::update_all

phpActiveRecord Incorrect DateTimeFormat

怎甘沉沦 提交于 2019-12-07 06:13:26
问题 When trying to create a record in a table using phpActiveRecord I get the following error: Invalid datetime format: 1292 Incorrect datetime value: '2013-06-20 11:59:08 PDT' for column 'created_at' The code that is running: $new_cart = new QuoteRequest(); $new_cart->status = "cart"; $new_cart->save(); I've tracked this down to the pertinent lines in phpActiveRecord. The file Connection.php, lines 55-59: /** * Database's datetime format * @var string */ static $datetime_format = 'Y-m-d H:i:s T'

PHP ActiveRecord doesn't seem to use my custom attribute

别等时光非礼了梦想. 提交于 2019-12-06 11:59:36
问题 I have a model defined as follows: class User extends ActiveRecord\Model { function get_name() { return $this->first_name . " " . $this->surname; } } however when I show $item->attributes(); then name doesn't appear. Am I being an idiot here? If so, how do I get my custom attributes into the model? Thanks, Gareth 回答1: Here's my simple solution. I've overriding the attributes method and adding any methods that start with "get_attribute_" so I can use them during serialization: class BaseModel

PHP ActiveRecord doesn't seem to use my custom attribute

僤鯓⒐⒋嵵緔 提交于 2019-12-04 17:24:11
I have a model defined as follows: class User extends ActiveRecord\Model { function get_name() { return $this->first_name . " " . $this->surname; } } however when I show $item->attributes(); then name doesn't appear. Am I being an idiot here? If so, how do I get my custom attributes into the model? Thanks, Gareth Here's my simple solution. I've overriding the attributes method and adding any methods that start with "get_attribute_" so I can use them during serialization: class BaseModel extends ActiveRecord\Model { public function attributes() { $attrs = parent::attributes(); $modelReflector =

Activerecord-association: create new object (find class)

余生颓废 提交于 2019-12-03 04:04:22
I have an model with a relation, and I want to instantiate a new object of the relations type. Example: A person has a company, and I have a person-object: now I want to create a company-object. The class of the companyobject is defined in the relation, so I don't think I should need to 'know' that class, but I should be able to ask the person-object to provide me with a new instance of type company? But I don't know how. This is -I think- the same question as New model object through an association , but I'm using PHPActiveRecord , and not the ruby one. Reason behind this: I have an abstract

How to query sql with active record for dates between specified times

女生的网名这么多〃 提交于 2019-11-29 03:52:52
I have a database that I want to pull only certain rows that have dates in specified ranges. I'm not sure how to do this properly in active record. Right now it looks like I'm running a standard mysql query inside of an active record query. I hope this gives you the idea of what I'm looking for. I would also like to be able to get rows with anything before today, including today and 3 days in the future. $query = $this->db->query("SELECT * FROM 'topics_list' . 'topic date' WHERE DATE(order_datetime) BETWEEN '2012-10-01' AND '2012-10-3'"); this is the way . but according to the DATE format you

How to query sql with active record for dates between specified times

眉间皱痕 提交于 2019-11-27 22:17:02
问题 I have a database that I want to pull only certain rows that have dates in specified ranges. I'm not sure how to do this properly in active record. Right now it looks like I'm running a standard mysql query inside of an active record query. I hope this gives you the idea of what I'm looking for. I would also like to be able to get rows with anything before today, including today and 3 days in the future. $query = $this->db->query("SELECT * FROM 'topics_list' . 'topic date' WHERE DATE(order