Sunday, February 8, 2015

Re: Action a postLink without refreshing page (AJAX?)

Maybe this helps?
http://stackoverflow.com/questions/9750326/intercept-cake2-postlink-form-posts-with-jquery


Am Samstag, 7. Februar 2015 17:34:38 UTC+1 schrieb MarkB:
Hi,

My first Cake project (and first major non-intranet web project!) is a fairly complex event management system for a month-long city-wide science festival my employer runs, involving about 120 events.

I have added the ability to add (and remove) events to a wishlist from a postLink, which works well on the event view page, but is annoying for users when clicking the 'Add to wishlist' link in the events listings page, as the page refreshes and they may have to scroll down to continue browsing where they left off.

I've been messing about with PHP for years, but have little Javascript experience and nothing AJAX-based. Time is getting tight, so I'm wondering if there is anyone who can help me achieve this? Thanks!

This is the code I use in my view:

 if ($wishlisted == NULL){
 echo $this
->Form->postLink('Add to wishlist', array('action' => 'wishadd', $event['Event']['id']));
 
} else {
 echo
"On your wishlist " . $this->Form->postLink('Remove', array('action' => 'wishlistremove', $wishlisted));
 
}




This is my Controller code:

public function wishadd($id) {
if ($this->request->is('get')) {
        throw new MethodNotAllowedException();
    }
$user_id = $this->Auth->user('id');
if ($user_id == NULL) {
$this->Session->setFlash('You must be logged in to add an event to a wishlist!');
return $this->redirect(array('action' => 'view',$id));
}
$currentYear = $this->getSettings('year');
$event = $this->Event->findById($id);
$conditions = array('Wishlist.year' => $currentYear,'Wishlist.event_id' => $id,'Wishlist.user_id' => $this->Auth->user('id'));
$wishlisted = $this->Event->Wishlist->find('count',array('conditions' => $conditions));
if ($wishlisted > 0) {
$this->Session->setFlash('This event is already on your wishlist.');
return $this->redirect($this->referer());
}
if ($this->request->is('post')) {
$this->Event->Wishlist->create();
$wishlist_id = $this->Event->Wishlist->getInsertID();
$this->Event->Wishlist->saveField('year', $currentYear);
$this->Event->Wishlist->saveField('event_id', $id);
$this->Event->Wishlist->saveField('proposal_id', $event['Event']['proposal_id']);
$this->Event->Wishlist->saveField('user_id', $user_id);
$this->Session->setFlash('This event has been added to your wishlist.');
return $this->redirect($this->referer());
} else {
$this->Session->setFlash('Unable to add to your wishlist. Please try again.');
return $this->redirect($this->referer());
}
}






--
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 cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

empty controller/component directory

Hi,

I just started with this excellent tool and I am trying to use the login script as described by the example on the site (http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html).
The blog script is up and running, no problems there.
When I try to create a new user I receive the message "Error: Class 'BlowfishPasswordHasher' not found"
There do not seem to be any relevant posts about this issue. I have found that my complete app/controller/component directory is empty. Is this normal?
I have downloaded the script from the official website and again from github. Both times the directory was empty.
Am I supposed to install this add-on? Where can I download it?

v.

--
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 cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

CakePHP 3 Plugin not working (controller file not found)

I followed all the instrucitons, even tried baking a plugin. But each time I reference the plugin (eg. http://localhost/contact_manager/contacts) it says Controller not found. All the files have been created and placed in the proper location. It will say file not found in /plugins/ContactManager/src/Controller/ContactsController.php and I've tripled checked, of course, that the file exists. I also created the Table file - nada.

It's loading the plugin properly because when I remove, say bootstrap.php inside the plugin, it will say the bootstrap file is not found inside the plugin.

Any ideas?

--
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 cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

Saturday, February 7, 2015

Action a postLink without refreshing page (AJAX?)

Hi,

My first Cake project (and first major non-intranet web project!) is a fairly complex event management system for a month-long city-wide science festival my employer runs, involving about 120 events.

I have added the ability to add (and remove) events to a wishlist from a postLink, which works well on the event view page, but is annoying for users when clicking the 'Add to wishlist' link in the events listings page, as the page refreshes and they may have to scroll down to continue browsing where they left off.

I've been messing about with PHP for years, but have little Javascript experience and nothing AJAX-based. Time is getting tight, so I'm wondering if there is anyone who can help me achieve this? Thanks!

This is the code I use in my view:

 if ($wishlisted == NULL){
 echo $this
->Form->postLink('Add to wishlist', array('action' => 'wishadd', $event['Event']['id']));
 
} else {
 echo
"On your wishlist " . $this->Form->postLink('Remove', array('action' => 'wishlistremove', $wishlisted));
 
}




This is my Controller code:

public function wishadd($id) {
if ($this->request->is('get')) {
        throw new MethodNotAllowedException();
    }
$user_id = $this->Auth->user('id');
if ($user_id == NULL) {
$this->Session->setFlash('You must be logged in to add an event to a wishlist!');
return $this->redirect(array('action' => 'view',$id));
}
$currentYear = $this->getSettings('year');
$event = $this->Event->findById($id);
$conditions = array('Wishlist.year' => $currentYear,'Wishlist.event_id' => $id,'Wishlist.user_id' => $this->Auth->user('id'));
$wishlisted = $this->Event->Wishlist->find('count',array('conditions' => $conditions));
if ($wishlisted > 0) {
$this->Session->setFlash('This event is already on your wishlist.');
return $this->redirect($this->referer());
}
if ($this->request->is('post')) {
$this->Event->Wishlist->create();
$wishlist_id = $this->Event->Wishlist->getInsertID();
$this->Event->Wishlist->saveField('year', $currentYear);
$this->Event->Wishlist->saveField('event_id', $id);
$this->Event->Wishlist->saveField('proposal_id', $event['Event']['proposal_id']);
$this->Event->Wishlist->saveField('user_id', $user_id);
$this->Session->setFlash('This event has been added to your wishlist.');
return $this->redirect($this->referer());
} else {
$this->Session->setFlash('Unable to add to your wishlist. Please try again.');
return $this->redirect($this->referer());
}
}






--
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 cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

Friday, February 6, 2015

cakephp the rule validation function run twice

whene i use this code it's repeat the function isExif_imagetype
        'ProfileImage' => array(
           'rule'       => 'isExif_imagetype', // ou bien : array('nomRegle', 'parametre1', 'parametre2' ...)
         'message'    => 'Votre message d\'erreur'
           ),
, but whene i add         'on'         => 'create', 
 it's does't repeat.
and for example whene i debug i got twice message. how to make it's run without repeating ??

--
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 cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

Correct model associations

I am trying to bind 3 tables and I am having problems with proper relations. 
Table users (pk id), books (pk id), users_books (user_id, book_id), comments (pk and foreign key book_id, user_id -> with reference to users_books)

Here are the models:

Book

  public $hasAndBelongsToMany = array(
      'User' =>
      array(
        'className' => 'User',
          'joinTable' => 'users_books',
            'foreignKey' => 'book_id',
            'associationForeignKey' => 'user_id',
            'unique' => true,
        'conditions' => '',
        'fields' => '',
        'order' => '',
        'limit' => '',
        'offset' => '',
        'finderQuery' => '',
      //  'with' => 'UserBook'
    ),);

    public $hasMany = array('Comment'=>array('className'=>'Comment'));

Comment:

  public $belongsTo = array (
    'Book' => array (
'className'=>'Book',

    )
  );


When I try to save with the saveAll method I got: 

Error: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`metabook`.`comments`, CONSTRAINT `comments_ibfk_1` FOREIGN KEY (`user_id`, `book_id`) REFERENCES `users_books` (`user_id`, `book_id`))  

I know that this is not according to the cakephp conventions, but what I can do to bind those tables?

--
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 cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

Thursday, February 5, 2015

Re: Cake v2.x -- Looking to return rendered view to the Controller

It looks like `Controller::render()` sets the body on the CakeResponse object and then returns the CakeResponse object: http://api.cakephp.org/2.6/source-class-Controller.html#922-962. I would imagine you could access the rendered view like so:
    public function test()
    {
       
$this->render('/Emails/html/test', false);
        $emailBody
= $this->response->body;
        // Do what you want with $emailBody here
   
}



On Wednesday, February 4, 2015 at 5:33:35 PM UTC-5, BrendonKoz wrote:
For various reasons I had decided to use a 3rd party email library within my current CakePHP project. I thought that it might be nice to use CakePHP's Views to create templating for my emails and take advantage of layouts too. Unfortunately I'm stumped on just how to retrieve the rendered output of a view back to the Controller method.

I've tried the following:

    public function test() {
        $this
->layout = false;
       
#$this->view = '/Emails/html/test.ctp';
        $var
= $this->render('/Emails/html/test', false);
        pr
($var->_body); die();
   
}

$var->_body is protected (as denoted by the underscore). I saw no other property within the $var variable that contained the "body" code within my (template) view.

Are there any ways to do this that I'm just not seeing? If so, can I safely presume that layouts would be handled in a similar fashion?

Thank you for any possible help...

--
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 cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.