PHP ActiveRecord: Helphttp://www.phpactiverecord.org/2018-01-26T07:13:49-05:00An easy to use ORM for PHP
Redmine Help: Fatal error: Uncaught exception 'ActiveRecord\UndefinedPropertyException' with message 'Und...http://www.phpactiverecord.org/boards/4/topics/20742018-01-26T07:13:49-05:00jonny rotten
<p>Anyone can help me ?</p>
<p>I have MVC structure and i have problem with insert function from activerecord model</p>
<p>my class ===><br />public function Insert() {</p>
<pre><code>$data = array(<br /> 'kdname' => $_POST['artist'],<br /> 'kdvname' => $_POST['trank'],<br /> 'link' => $_POST['link']<br /> );<br /> print_r($data);</code></pre>
<pre><code>$insert = \APP\Models\Model_home::createit($data);</code></pre>
<pre><code>return $insert;<br /> }</code></pre>
<p>model ===></p>
<p><?php<br />namespace APP\Models;</p>
<p>use ActiveRecord\Model;</p>
<p>class Model_home extends Model {<br /> //put your code here<br /> public $data;</p>
<pre><code>static $table_name = "tblkunden";</code></pre>
<pre><code>static function listar()
{<br /> $data = Model_home::all();<br /> return $data;<br /> }</code></pre>
<pre><code>static function createit($data){<br /> print_r($data);</code></pre>
<pre><code>$result = Model_home::create($data);<br /> var_dump($result);<br /> $result->create($data);<br /> //self::create($data);</code></pre>
<pre><code>}</code></pre>
<p>}</p> Help: has many through questionhttp://www.phpactiverecord.org/boards/4/topics/20722017-11-16T08:51:18-05:00Bob Anderson
<p>Hi,</p>
<pre><code>I have three models:</code></pre>
<p>Bookmark (with fields: id, url)<br />ContentTag (with fields: model, model_id, tag_id)<br />Tag (with fields: id, taglabel)</p>
<p>how do I define the static $has_many array so I have an array tags in model Bookmarks.</p>
<p>You can find all tags for a bookmark by checking model ContenTag with model = "BOOKMARK" and model_id = id from tabel Bookmark. And then you can get the Tag using ContentTag->tag_id = Tag->id.</p>
<p>I have tried several ways but can't seem to get it right.</p>
<p>Does anyone have a simple example for this type of stuff? Of is it impossible since I have a foreign_key option in the contenttag association?</p> Help: RE: Multiple Database Connectionshttp://www.phpactiverecord.org/boards/4/topics/1660?r=2071#message-20712017-11-02T02:56:53-04:00oliver russell
<p>Alan James wrote:</p>
<blockquote>
<p>I'm sure someone has asked this question but I can't find the answer.</p>
<p>How would one connect to a different database for each model they create?</p>
</blockquote>
<p>Using this code for multiple database connection in codeigniter (<a class="external" href="https://www.cloudways.com/blog/connect-multiple-databases-codeigniter/">https://www.cloudways.com/blog/connect-multiple-databases-codeigniter/</a>)</p>
<p>function db_calling_model_method()</p>
<p>{</p>
<p> $otherdb = $this->load->database('anotherdb', TRUE); // the TRUE paramater tells CI that you'd like to return the database object.</p>
<p> $query = $otherdb->select('column_one, column_two')->get('table');</p>
<p> var_dump($query);</p>
<p>}</p> Help: RE: RE: Saving Date to Mysql Problemhttp://www.phpactiverecord.org/boards/4/topics/531?r=2070#message-20702017-10-11T11:22:32-04:00Stefan Djokic
<p>For all of those still struggling with this issue.<br />I've made a pull request which will hopefully help you solve this.<br /><a class="external" href="https://github.com/jpfuentes2/php-activerecord/pull/585">https://github.com/jpfuentes2/php-activerecord/pull/585</a></p> Help: RE: Can't get GroupName using Associationshttp://www.phpactiverecord.org/boards/4/topics/2064?r=2068#message-20682017-03-03T14:52:52-05:00Israel Sousa
<p>I have the same question, have you find the answer?</p> Help: Cannot change $primary_keyhttp://www.phpactiverecord.org/boards/4/topics/20672017-01-03T12:20:13-05:00Vasek Keberdle
<p>Hi, <br />I cannot change $primary_key of entity.<br />After save is still in database original value.</p>
<pre><code>$ended_uniq_customer_actions = \Db\ActionsToCustomersUniq::find('all', array(<br /> 'conditions' => array(<br /> 'customers_uniq_id = ?',<br /> 16728<br /> )<br /> ));</code></pre>
<pre><code>$ended_uniq_customer_actions[0]->customers_uniq_id = 15892;<br /> $ended_uniq_customer_actions[0]->save();</code></pre>
<p>class ActionsToCustomersUniq extends ActiveRecord\Model
{<br /> static $table_name = 'crm_actions_to_customers_uniq';<br /> static $primary_key = array('actions_id','customers_uniq_id');</p>
<p>}</p>
<p>CREATE TABLE IF NOT EXISTS `crm_actions_to_customers_uniq` (<br /> `actions_id` int(11) NOT NULL DEFAULT '0',<br /> `updated_at` datetime DEFAULT NULL,<br /> `created_at` datetime DEFAULT NULL,<br /> `customers_uniq_id` int(11) NOT NULL DEFAULT '0',<br /> PRIMARY KEY (`customers_uniq_id`,`actions_id`)<br />) ENGINE=InnoDB DEFAULT CHARSET=utf8;<br /><ins><del>----------</del></ins>-------------------+
| actions_id | customers_uniq_id |<br /><ins><del>----------</del></ins>-------------------+
| 3 | 16728 |<br /><ins><del>----------</del></ins>-------------------+</p>
<pre><code>mysql Ver 14.14 Distrib 5.5.53, for debian-linux-gnu (x86_64) using readline 6.3</code></pre>
<p>Thank You in advance for help</p> Help: RE: Saving Date to Mysql Problemhttp://www.phpactiverecord.org/boards/4/topics/531?r=2066#message-20662016-12-07T08:21:47-05:00Jos Faber
<p>That static property is not available anymore in stable build 1.0, so that won't work.<br />The format is, as Marcellus pointed out 5 years ago, hardcoded.<br />Any other solutions other than changing core code?</p> Help: RE: Can't get GroupName using Associationshttp://www.phpactiverecord.org/boards/4/topics/2064?r=2065#message-20652016-09-28T05:58:57-04:00McLotos McLotos
<p>Project is dead?</p> Help: Can't get GroupName using Associationshttp://www.phpactiverecord.org/boards/4/topics/20642016-09-28T05:46:09-04:00McLotos McLotos
<p>Hi!<br />Help pls!<br />I can't get a group name using associations.</p>
<p>namespace Lotos\Models;<br />use Lotos\Vendors\ActiveRecord\Model as Model;</p>
<p>class AclUser extends Model {<br /> static $belongs_to = array(<br /> array('Lotos\Models\AclGroupsName', 'select'=>'groupName')<br /> );<br />}</p>
<p>namespace Lotos\Models;<br />use Lotos\Vendors\ActiveRecord\Model as Model;</p>
<p>class AclGroupsName extends Model {<br /> static $has_many = array(<br /> array('Lotos\Models\AclUser')<br /> );<br />}</p>
<p>use Lotos\Models\AclUser as User;<br />$user = User:find_by_id('1');</p> Help: Update multiple rowshttp://www.phpactiverecord.org/boards/4/topics/20632016-08-06T14:32:42-04:00Grzegorz Polska
<p>Hi,<br />I have a simple question:<br />Is there any chance to update multiple rows in Active Records by like that:<br /><pre class="code">
$images = Galleries::all([
'conditions' => [
'articles_id IS NULL AND users_id = ?',
Kernel::$app->auth->user->id
]
])
$images->articles_id = $article->id;
$images->save();
</pre></p>
<p>or there is only method like that:<br /><pre class="code">
Galleries::update_all([
'set' => [
'articles_id' => $article->id
],
'conditions' => [
'articles_id IS NULL AND users_id = ?',
Kernel::$app->auth->user->id
]
]);
</pre><br />Best cheers!</p> Help: Different results between PHP 5.6 and 7.0 with the fields from joined tablehttp://www.phpactiverecord.org/boards/4/topics/20612016-06-12T05:50:39-04:00Arnaud Morel
<p>Hello, i have different results between PHP 5.6 and 7.0 with the fields from joined table.<br />With PHP 5.6 the empty test is ok, but not with PHP 7.0 :</p>
<pre class="code">
<?php
// PHP 7.0.7 (Debian Stretch)
$attributes = array(
'order' => 'id DESC',
'limit' => 25
);
$logs = Log::all($attributes);
foreach ($logs as $log)
{
// $log->user->description = 'bla1';
$var = $log->user->description;
// don't print if joined table !
if ( !empty($log->user->description) )
{
print "A:{$log->user->description}";
}
// print if $log->user->description is in $var
if ( !empty($var) )
{
print "B:{$log->user->description}";
}
// $log->action = 'add';
//
// print if field is not joined table
if ( !empty($log->action) )
{
print "Action:{$log->action}";
}
}
?>
</pre>
<p>MySQL database :</p>
<pre class="code">
CREATE TABLE IF NOT EXISTS `users` (
`id` INTEGER unsigned NOT NULL AUTO_INCREMENT,
`login` VARCHAR(32) NOT NULL,
`description` VARCHAR(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;
CREATE TABLE IF NOT EXISTS `logs` (
`id` INTEGER unsigned NOT NULL AUTO_INCREMENT,
`user_id` INTEGER unsigned NOT NULL,
`action` ENUM('add','change') DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;
INSERT INTO `users` (`id`, `login`, `description`) VALUES
(1, 'fake1', 'bla1'),
(2, 'fake2', NULL);
INSERT INTO `logs` (`id`, `user_id`, `action`) VALUES
(1, 1, 'add'),
(1, 1, NULL);
</pre>
<p>PHP ActiveRecord models :</p>
<pre class="code">
//User.php
<?php
class User extends ActiveRecord\Model
{
}
?>
</pre>
<pre class="code">
//Log.php
<?php
class Log extends ActiveRecord\Model
{
static $belongs_to = array(
array('user')
);
}
?>
</pre>
<p>Thank you</p> Help: RE: Get last n record of tablehttp://www.phpactiverecord.org/boards/4/topics/2053?r=2060#message-20602016-05-18T15:12:32-04:00Alexander Matrosov
<p>example<br /><pre class="code">
<?php
$guest = new Guestbook();
$guest->token = Request::input('token', true);
$guest->captcha = Request::input('captcha');
$guest->user_id = User::get('id');
$guest->text = Request::input('text');
$guest->ip = App::getClientIp();
$guest->brow = App::getUserAgent();
// after save
if ($guest->save()) {
//last insert id
var_dump($guest->id);
</pre></p> Help: RE: PHP7 Incorrect datetime value: '2016-05-14 19:34:37 UTC' http://www.phpactiverecord.org/boards/4/topics/2057?r=2059#message-20592016-05-18T15:03:51-04:00Alexander Matrosov
<p>after the initialization list the following code</p>
<p>ActiveRecord\Connection::$datetime_format = 'Y-m-d H:i:s';</p> Help: RE: PHP7 Incorrect datetime value: '2016-05-14 19:34:37 UTC' http://www.phpactiverecord.org/boards/4/topics/2057?r=2058#message-20582016-05-14T16:04:27-04:00Vasek Keberdle
<p>Help edit Connection.php<br /> public function datetime_to_string($datetime)
{<br /> return $datetime->format('Y-m-d H:i:s');<br /> }</p> Help: PHP7 Incorrect datetime value: '2016-05-14 19:34:37 UTC' http://www.phpactiverecord.org/boards/4/topics/20572016-05-14T15:43:05-04:00Vasek Keberdle
<p>Hi, I am testing app on PHP7 ( on PHO5.6 works well) and i get error :</p>
<p>$database->date = new \DateTime();</p>
<p>Fatal error: Uncaught ActiveRecord\DatabaseException: 22007, 1292, Incorrect datetime value: '2016-05-14 19:34:37 UTC' for column 'date'<br /> at row 1 in ,includes/classes/php-activerecord/lib/Connection.php:276 <br /> Stack trace: <br /> #0 ,includes/classes/php-activerecord/lib/Table.php(328): ActiveRecord\Connection->query('UPDATE `zs_min_...', Array) <br /> #1 ,includes/classes/php-activerecord/lib/Model.php(844): ActiveRecord\Table->update(Array, Array) <br /> #2 ,includes/classes/php-activerecord/lib/Model.php(758): ActiveRecord\Model->update(true) <br /> #3 ,includes/classes/MyCLass.php(128): ActiveRecord\Model->save()</p>
<p>mysql --version<br />mysql Ver 14.14 Distrib 5.6.27, for Linux (x86_64) using EditLine wrapper<br />PHP Version => 7.0.0-dev</p>