ok that brings me to the next question.

How do I get $article = $this->Articles->newEntity($this->request->data);
to use the Entity class I have created in  App/Model/ArticleEntity.php ?
Doesn't the controller automagically include it, What is the convention for
Entity classes?

Tarique



On Wed, Mar 12, 2014 at 12:53 PM, José Lorenzo <[email protected]> wrote:

> This could possibly be the most difficult part to understand in 3.0 and
> may be subject to change if it turns out to be too complicated. All
> properties in the entities are protected by default against mass
> assignment, you need to modify your Article entity in order to let CakePHP
> know what properties can be assigned by newEntity:
>
> class Article extends Entity {
>
>   protected $_accessible = ['title' => true, 'body' => true];
>
> }
>
> or if you just don't care (not recommended):
>
> class Article extends Entity {
>
>   protected $_accessible = ['*' => true];
>
> }
>
> The latter can be seen as a Eloquent::unguard();
>
> On Wednesday, March 12, 2014 6:30:45 AM UTC+1, Dr. Tarique Sani wrote:
>>
>> Wonder why saving is failing
>>
>> I am doing
>>
>> $article = $this->Articles->newEntity($this->request->data);
>>
>> if ($this->Articles->save($article)) {
>>                 $this->Session->setFlash(__('Your article has been
>> saved.'));
>>                 return $this->redirect(['action' => 'index']);
>> }
>>
>> $this->Session->setFlash(__('Unable to add your article.'));
>>
>>
>> debug($this->request->data);
>>
>> gives
>>
>>  [
>> 'title' => 'Test Title',
>> 'body' => 'This is the body'
>> ]
>>
>>
>> but debug($article);
>>
>> give
>>
>> object(Cake\ORM\Entity) {
>>
>> 'new' => null,
>>  'accessible' => [],
>> 'properties' => [],
>> 'dirty' => [],
>>  'virtual' => [],
>> 'errors' => []
>>
>> }
>>
>> What can possibly be wrong. I am guessing the title and body should
>> appear as properties of the newly created entity without which the saving
>> will not happen
>>
>> I did a composer update just now - so I do have the latest code.
>>
>> Cheers
>> Tarique
>>
>> --
>> =============================================================
>> The Conference Schedule Creator : http://shdlr.com
>>
>> PHP for E-Biz : http://sanisoft.com
>> =============================================================
>>
>  --
> Like Us on FaceBook https://www.facebook.com/CakePHP
> Find us on Twitter http://twitter.com/CakePHP
>
> ---
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/cake-php.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
=============================================================
The Conference Schedule Creator : http://shdlr.com

PHP for E-Biz : http://sanisoft.com
=============================================================

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

Reply via email to